Access to @android: id / list ListView from code

In my Android app, I add a ListView element (for example) to the main.xml layout file as follows:

<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 identifier in a layout file?

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

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

Thanks in advance!

+8
android android-layout android-listview android-xml
source share
2 answers

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

+16
source share

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

Or:

 (ListView)findViewById(android.R.id.list); 
+19
source share

All Articles