Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing @android:id/list ListView from code

In my Android application, I add a ListView element (for example) in the main.xml layout file this way:

<ListView android:id="@+id/myList">

Then I can access it from my MainActivity using:

final ListView resultList = (ListView) findViewById(R.id.myList);

But how can I access such a ListView if I use the following ID in the layout file?

<ListView android:id="@android:id/list">

I want to access it from my MainActivity (which extends ListActivity).

Thanks in advance!

like image 548
caw Avatar asked Aug 05 '11 17:08

caw


2 Answers

you can get it with ListView list = getListView(); from within your ListActivity

like image 110
dten Avatar answered Sep 20 '22 06:09

dten


you can get it with ListView list = getListView();

Or:

(ListView)findViewById(android.R.id.list);
like image 23
Austin Hanson Avatar answered Sep 21 '22 06:09

Austin Hanson