ListView控件上述&lt;&包括GT; [英] ListView in <include>
问题描述
您好,我没有一个code的问题,因为我还没有对如何做到这一点在我的脑海什么。我的问题是:
Hello I don't have a code problem, because I still don't have anything on my mind on how to do it. My question is:
我有一个的ListView
我的活动创建
与 ListAdapter
我想这个活动
显示与此的ListView
新的布局。
I have a ListView
created on my Activity
with ListAdapter
and I want this Activity
to show new layout with this ListView
.
为什么同一个活动?
- 因为我要保持我的
OnItemClickListener
并有充分的工作清单。
- Because I want to keep my
OnItemClickListener
and have a fully working list.
为什么我想列出?
- 因为我想更好的
UI
我的应用程序视图。
- Because I want better
UI
view for my app.
如果我调用另一个活动
使用包含新的布局,的ListView
,以及的ListView
,因为没有活动取得列表内容是空的。
If I call another Activity
with new layout that contains that ListView
, well, ListView
will be empty because there is no activity to get list contents.
推荐答案
我觉得你是错误理解的Android是如何工作的?
I think you are mis-understanding how Android works...
您可以有多个列表视图多种活动。该列表视图都可以使用相同的布局,也可以使用不同的布局。他们还可以每个人都有自己onItemClickListener。
You can have multiple activities with multiple listviews. The listviews can all use the same layout or they can use different layouts. They can also each have their own onItemClickListener.
这是我的一个项目一个例子:
An example from one of my projects:
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的方法做完全不同的事情。
So that's two different activities, with two different lists, using two different listviews, each with their own onListItemClick methods that do completely different things.
这篇关于ListView控件上述&lt;&包括GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!