你好,我没有代码问题,因为我仍然没有任何关于如何做它的想法。我的问题是:
我用ListView在我的Activity上创建了一个ListAdapter,我希望这个Activity用这个ListView显示新的布局。
为什么是同样的活动?
OnItemClickListener并且有一个完整的工作列表。我为什么要列出?
UI视图。如果我使用包含该Activity的新布局调用另一个ListView,那么ListView将为空,因为没有获取列表内容的活动。
发布于 2012-05-04 00:16:25
所以..。您希望相同的活动在用户交互之后显示不同的视图?也许一个ViewFlipper可能会有所帮助。
发布于 2012-05-04 04:01:30
我觉得你误解了机器人的工作原理.
您可以使用多个列表视图进行多个活动。列表视图都可以使用相同的布局,也可以使用不同的布局。他们也可以各自拥有自己的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();
}这是两个不同的活动,有两个不同的列表,使用两个不同的listview,每个都有自己的onListItemClick方法,这些方法可以完成完全不同的事情。
https://stackoverflow.com/questions/10441004
复制相似问题