首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListView in <include>

ListView in <include>
EN

Stack Overflow用户
提问于 2012-05-04 00:04:36
回答 2查看 142关注 0票数 0

你好,我没有代码问题,因为我仍然没有任何关于如何做它的想法。我的问题是:

我用ListView在我的Activity上创建了一个ListAdapter,我希望这个Activity用这个ListView显示新的布局。

为什么是同样的活动?

  • 因为我想保留我的OnItemClickListener并且有一个完整的工作列表。

我为什么要列出?

  • 因为我想要我的应用程序更好的UI视图。

如果我使用包含该Activity的新布局调用另一个ListView,那么ListView将为空,因为没有获取列表内容的活动。

EN

回答 2

Stack Overflow用户

发布于 2012-05-04 00:16:25

所以..。您希望相同的活动在用户交互之后显示不同的视图?也许一个ViewFlipper可能会有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2012-05-04 04:01:30

我觉得你误解了机器人的工作原理.

您可以使用多个列表视图进行多个活动。列表视图都可以使用相同的布局,也可以使用不同的布局。他们也可以各自拥有自己的onItemClickListener。

我的一个项目的一个例子:

代码语言:javascript
复制
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方法,这些方法可以完成完全不同的事情。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10441004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档