你好我没有代码问题,因为我仍然没有任何关于如何做的事。我的问题是:
我在ListView
上使用Activity
创建了ListAdapter
,我希望此Activity
能够使用此ListView
显示新的布局。
为什么同样的活动?
OnItemClickListener
并拥有完整的工作清单。为什么我要列出?
UI
视图。如果我使用包含Activity
的新布局调用另一个ListView
,那么ListView
将为空,因为没有活动可以获取列表内容。
答案 0 :(得分:0)
那么......你想让同一个活动在用户交互后显示不同的视图吗?也许ViewFlipper可能会有帮助。
答案 1 :(得分:0)
我认为你误解了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方法,这些方法完全不同。