Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use getListView() in Activity?

Tags:

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

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

what should I do?

like image 462
user65544 Avatar asked Jun 08 '11 07:06

user65544


People also ask

How to get data from ListView by clicking item on ListView?

Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });

What is ListActivity?

An activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results.


1 Answers

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:

setContentView(R.layout.your_layout);
ListView list = (ListView)findViewById(R.id.list);
list.addFooterView(view);

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

ListView list = getListView(); // OR you can do
ListView list = (ListView)findViewById(android.R.id.list);  //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"

like image 67
Adil Soomro Avatar answered Sep 23 '22 00:09

Adil Soomro