获取ListView的行ID从Android的SQLite数据库 [英] Getting the row ID of a listview from a Android SQlite database

查看:216
本文介绍了获取ListView的行ID从Android的SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了显示数据库中所有的人一个列表视图。但是,我怎么得到一个我选择这样的行ID我可以在信息来源传递到下一个活动。

I have created a listview which displays all the people in the database. But how do I get the row id of the one I select so I can pass that infomation to the next activity.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.load_game1);

    listContent = (ListView)findViewById(R.id.contentlist);

    mDbAdapter = new DbAdapter(this);
    mDbAdapter.open();
    Cursor cursor = mDbAdapter.fetchAll();
    startManagingCursor(cursor);
    String[] from = new String[]{DbAdapter.KEY_NAME, DbAdapter.KEY_ROWID};
    int[] to = new int[]{R.id.text};
    cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
    listContent.setAdapter(cursorAdapter);
    mDbAdapter.close();
    }

该款显示器

Which displays

现在我想点击一个名字从数据库中获取该行标识。

Now I want to click on a name get that row id from the database.

推荐答案

使用 setOnItemClickListener 列表视图那么你将获得所选项目的ID(项目编号从0开始,但数据库_id列是从1开始,所以你应该送的id + 1 ,请证实)。

Use setOnItemClickListener on your Listview then you will get the id of the selected item (item id start from 0 but Database _id column is start from 1 so you should send id+1, please confirm this).

和使用意图发送的ID。

And send the id using intents.

这篇关于获取ListView的行ID从Android的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆