Android
您好,我没有代码问题,因为我仍然没有任何关于如何做的想法。我的问题是: 我使用ListAdapter在我的活动上创建了一个ListView,我希望此活动使用此ListView显示新的布局 为什么要进行同样的活动 因为我想保留我的听众,并有一个完整的工作列表。 为什么我要列出 因为我希望我的应用程序有更好的UI视图。Android ,android,include,android-listview,listadapter,Android,Include,Android Listview,Listadapter,您好,我没有代码问题,因为我仍然没有任何关于如何做的想法。我的问题是: 我使用ListAdapter在我的活动上创建了一个ListView,我希望此活动使用此ListView显示新的布局 为什么要进行同样的活动 因为我想保留我的听众,并有一个完整的工作列表。 为什么我要列出 因为我希望我的应用程序有更好的UI视图。 如果我调用另一个具有包含该ListView的新布局的活动,那么ListView将为空,因为没有活动可以获取列表内容。。。。是否希望同一活动在用户交互后显示不同的视图?也许a会有所帮助
如果我调用另一个具有包含该ListView的新布局的活动,那么ListView将为空,因为没有活动可以获取列表内容。。。。是否希望同一活动在用户交互后显示不同的视图?也许a会有所帮助。我认为你对Android的工作原理理解错误 您可以使用多个列表视图进行多个活动。列表视图可以使用相同的布局,也可以使用不同的布局。他们也可以有自己的听众 我的一个项目中的一个示例:
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方法,这些方法执行完全不同的操作。很有可能,新活动中的代码与第一个活动一样填充其列表。你的问题也不是很清楚。我们很难说出你的要求。