在Android中的2.1
和2.3
它工作正常。但對於3.0
及以上findViewById
沒有找到第二個ListView
。我已經嘗試清理該項目,嘗試不使用ListActivity
,沒有任何幫助。有任何想法嗎?Android 3.0及以上版本中的兩個ListViews在一個活動中
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(List1Adaptor);
list1 = (ListView) findViewById(android.R.id.list);
list2 = (ListView) findViewById(R.id.ListView2);
list2.setAdapter(List2Adapter);//Null Pointer
}
main.xml中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/ListView2"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
</ListView>
</LinearLayout>
<RelativeLayout
android:id="@+id/listLayout_relativeLayout2"
android:layout_height="320dp"
android:layout_width="fill_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
您是否使用適配器? – njzk2 2012-04-24 16:45:48
是的,我做到了...... – Adri 2012-04-25 17:49:55