我有麻煩創建一個簡單的列表(一些可擴展列表已經工作)。當我做setListAdapter()
時,該應用程序崩潰。我的錯誤在哪裏?ListActivity,ListView和ListAdapter崩潰Android應用程序
Acivity:
public class UserListActivity extends ListActivity {
UserListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userlist);
mAdapter = new UserListAdapter(this);
setListAdapter(mAdapter);
registerForContextMenu(getListView());
}
}
適配器:
public class UserListAdapter implements ListAdapter {
private Context context;
private List<UserItem> users;
public UserListAdapter(Context c) {
context = c;
users = new Database(context).getAllUsers(); // this class is working properly
}
public int getCount() {
return users.size();
}
public Object getItem(int pos) {
return users.get(pos).getSimplified();
}
public long getItemId(int pos) {
return users.get(pos).getId();
}
public int getItemViewType(int arg0) {
return 0;
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
return null;
}
public int getViewTypeCount() {
return 0;
}
public boolean hasStableIds() {
return true;
}
public boolean isEmpty() {
return users.size() == 0;
}
public void registerDataSetObserver(DataSetObserver arg0) {
}
public void unregisterDataSetObserver(DataSetObserver arg0) {
}
public boolean areAllItemsEnabled() {
return false;
}
public boolean isEnabled(int arg0) {
return false;
}
}
查看:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#312843" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="82dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="@drawable/header_side" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="235dp"
android:layout_height="82dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/header" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView2"
android:background="#312843"
android:cacheColorHint="#312843"
android:fadeScrollbars="true" >
</ListView>
</RelativeLayout>
你有任何外在上? – Praveenkumar 2012-03-20 15:18:37