Android – how to use getListView() in Activity


In ListActivity is can use this.getListView().addFooterView(footerView);

but if I use Activity it can't use this.getListView()

what should I do?

Best Solution

Whenever you use Activity you set your_layout.xml as your Activity's ContentView. So the ListView should b in your_layout.xml.

That ListView should have an id attribute defined in xml file say: (android:id="@+id/list"). You get your ListView object some thing like this way:

ListView list = (ListView)findViewById(;

And when you use ListActivity you get your ListView by calling method

ListView list = getListView(); // OR you can do
ListView list = (ListView)findViewById(;  //consider the android prefix..

and please note that while defining any layout.xml for ListActivity you would have a ListView in your layout having id of something like this: android:id="@android:id/list"