onsdag 28 oktober 2009

Using Map and List in the same activity

One of Javas problems (not correct to call it a problem maybe) is the lack of support for multiple inheritance. This means that you cannot extend both for instance MapActivity and ListActivity from the same class. So how do you implement a map with a list then? It's easy!

The ListActivity is nothing more than a wrapper around the ListView. What it does is only making it slightly easier to use a listView but it doesn't give you any extra value.

Instead of using the getListView() of ListActivity you simply fetch your own declared ListView exactly the same way as you fetch any other view

ListView lv = (ListView) findViewById(R.id.my_list_view);

You can then use this in any way you prefer. Put an adapter to it by using setAdapter() instead for ListActivity.setListAdapter() (it does the same thing).

This actually took me a while to figure out since almost all tutorials and the examples always extends the ListActivity instead of using the raw view.

Inga kommentarer: