在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