Finding a ListView in Android
How do I findViewById for the following XML?
<ListView android:id="@android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
I need it to set a list adapter.
Your XML must look like this:
<ListView android:id="@+id/ListView_Name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
in your code:
ListView listview = (ListView) findViewById(R.id.ListView_Name);
findViewById(android.R.id.list)
The ids prefixed with android:
are all accessible under android.R.id
. Similarly @android:drawable
are accessible as android.R.drawable
, etc...
This basic example shows you how to use an ArrayAdapter with a ListView. You should really need to ever actually mess with the ListView itself, just the elements that are put in it.
http://developer.android.com/resources/tutorials/views/hello-listview.html
精彩评论