2011-09-07 38 views
0

我正試圖在一個活動上顯示兩個自定義列表視圖。但我很困惑如何處理onListItemClick和最重要的我怎麼可以設置ID如何在android中的一個活動中使用兩個自定義列表視圖?

@ ID /安卓列表

兩個在同一個活動列表?

如果任何人嘗試過在單個活動中使用兩個列表視圖,則任何鏈接都將提供示例代碼。在此先感謝...

+0

你解決了嗎?我有同樣的問題 – 2015-01-27 07:23:38

+0

感謝它的工作我投票了.. – 2015-01-27 07:59:12

回答

5

在XML只是定義了兩個列表視圖,如:

<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> 

在代碼中使用該命令將您的列表

ListView list1 = (ListView) findViewById(R.id.list1); 
ListView list2 = (ListView) findViewById(R.id.list2); 

,併爲他們兩個設置不同onItemClickListener,例如這樣:

list1.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      //... 

     } 
    }); 

和你做:)這種方式,喲你的活動無需延長ListActivity,只需Activity

+0

我有同樣的問題,你能幫忙嗎? – 2015-01-27 07:27:22

+0

感謝它的工作我投票了.. – 2015-01-27 07:58:45

+0

我怎麼刷新我的自定義適配器? – 2015-01-27 09:17:35

相關問題