Search code examples
androidlistviewlistactivity

How to implement two listview in ListActivity?


I know that when you want to use ListActivity it requires you to put list name in XML as "@android:id/list". In that case if I want to use two listview, how could I implement since it have the same id?


Solution

  • A listactivity with '@android:id/list' means a single, full-screen list in the center of the screen. If you want to use two listviews in your activity, you have to use different ids for them. Like:

    <LinearLayout android:layout_weight="1" 
                        android:layout_height="fill_parent" 
                        android:layout_width="fill_parent">
    
                    <ListView   android:id="@+id/list1" 
                                android:layout_height="fill_parent" 
                                android:layout_width="fill_parent">
    
                    </ListView>
                    <ListView   android:id="@+id/list2" 
                            android:layout_height="fill_parent" 
                            android:layout_width="fill_parent">
    
                    </ListView>
        </LinearLayout>