when extendin开发者_JAVA百科g listactivity it is must to have a @android:id/list
question 1> what if i want to implement 2 listviews then ids will be same @android:id/list.
question 2> in what scenario i should use @+id/listView1.
Thanks in advance.
Well, the ID is independant(unless you don't name them uniquely) so you'd use the "@+id/listView1" solution every time as far as I know. I did this on my own Android app and it worked just fine.
ListActivity
is basically a 'convenience' class which simply extends Activity
and has a single ListView
plus some convenience methods for handling it - there's nothing particularly special about it.
If you want an Activity
which has more than one ListView
then it would be better to simply create your own from scratch.
If you create a Xml with let's say a relativelayout that contains a imageview on the top and a listview in the middle and a button in the bottom. Then you need to set an uniqe ID for your listview to gain access to it. ex:
<ListView
android:"@+id/unique_listview"
android:layout_width="fill_parent"
android:layout_height="400px"
/>
Then you can customize and populate the listView with this:
ListView myList = (ListView) findViewById(R.id.unique_listview);
myList.setAdapter(new myListAdapter(this));
private class myListAdapter extends BaseAdapter {
....
}
精彩评论