How to use two custom list views on one activity in android?
I am trying to show two custom listviews on one activity. But I am confused how to handle onListItemClick and most important how I can set the ID
@id/android:list
for both the lists on the same activity?
If any one have tried with two list views on single activity, any link, sample code will be helpf开发者_开发问答ul. Thanks in advance...
Just define two ListViews in your XML, like:
<LinearLayout android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/list1"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" />
<ListView android:id="@+id/list2"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" />
</LinearLayout>
In your code use this command to assign your Lists
ListView list1 = (ListView) findViewById(R.id.list1);
ListView list2 = (ListView) findViewById(R.id.list2);
and for both of them set a different onItemClickListener
, for example this way:
list1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//...
}
});
and you are done :) This way, your activity don't need to extend ListActivity
, just Activity
.
精彩评论