我认为您误解了Android的工作原理...
您可以有多个带有多个列表视图的活动。列表视图都可以使用相同的布局,也可以使用不同的布局。他们也可以各自拥有自己的 onItemClickListener。
我的一个项目中的一个例子:
public class BrowseSetups extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDBHelper = new DBAdapter(this);
mDBHelper.open(DBAdapter.MAIN_DATABASE_NAME, DBAdapter.MAIN_DATABASE_VERSION);
setupsCursor = mDBHelper.fetchSearchSetups(find, column);
this.startManagingCursor(setupsCursor);
String[] from = new String[] { DBAdapter.SETUP_PART };
int[] to = new int[] { R.id.ListItem1 };
SimpleCursorAdapter tools = new SimpleCursorAdapter(this,
R.layout.listlayout, setupsCursor, from, to);
setListAdapter(tools);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
setupsCursor.moveToPosition(position);
Intent myIntent = new Intent(BrowseSetups.this, BrowseTools.class);
BrowseSetups.this.startActivity(myIntent);
}
}
public class BrowseTools extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDBHelper = new DBAdapter(this);
mDBHelper.open(DBAdapter.MAIN_DATABASE_NAME, DBAdapter.MAIN_DATABASE_VERSION);
toolsCursor = mDBHelper.fetchAllTools();
this.startManagingCursor(toolsCursor);
String[] from = new String[] { DBAdapter.TOOL_ROWID,
DBAdapter.TOOL_DESCRIPTION };
int[] to = new int[] { R.id.ListItem1, R.id.ListItem2 };
SimpleCursorAdapter tools = new SimpleCursorAdapter(this,
R.layout.listlayoutdouble, toolsCursor, from, to);
setListAdapter(tools);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
toolsCursor.moveToPosition(position);
String Tool = "Tool #: " + id;
String Description = "Description: "
+ toolsCursor.getString(toolsCursor
.getColumnIndex(DBAdapter.TOOL_DESCRIPTION));
String Location = "Location: "
+ toolsCursor.getString(toolsCursor
.getColumnIndex(DBAdapter.TOOL_LOCATION));
AlertDialog locationAlert = new AlertDialog.Builder(this).create();
locationAlert.setTitle("Tool Information");
locationAlert.setMessage(Tool + "\n" + Description + "\n" + Location);
locationAlert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
locationAlert.show();
}
所以这是两个不同的活动,有两个不同的列表,使用两个不同的列表视图,每个都有自己的 onListItemClick 方法,它们做完全不同的事情。