开发者

how to get the respective value from a database table where one of the column values are displayed in a list view

I have created a table named train_table in SQLite database with 3 columns. they are train_id, train_no and train_name. Now, i wrote a class in which i displayed the train_开发者_运维技巧name in a list view. how do i get the related train_no in the next page? can anyone help me in sorting this problem.? Thanks in advance


Presumably "next page" you mean another view?

You could (assuming that the train_names are unique) create another SQLite query to re-read the database and retrieve the train_id into a local variable before switching to the "next page" view.


Assuming you're using a ListActivity, the fourth parameter in the onListItemClick signature is the row id of the record in your table:

onListItemClick(ListView  l, View  v, int position, long id)

You can use this id to get the full record (all three column fields). The following SQLite statement could be called by a method you create to query the database for the record:

select * from train_table where train_id = id

If you're not using a ListActivity then I'm assuming you have set up a AdapterView.OnItemClickListener for the ListView, in which case you'd have the following function defined:

onItemClick(AdapterView<?>  parent, View  view, int position, long id)

In this case you would still use the id to get your record.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜