assigning hidden values to a listview item

前端 未结 3 1695
感动是毒
感动是毒 2021-02-03 12:42

I have an activity that extends ListView. I populate my list with the results of a query to the sqlite database. A list element consists of start_time, end_time, client_name an

3条回答
  •  不思量自难忘°
    2021-02-03 13:07

    You should try to loosen yourself from the web development frame of mind a little bit. There is no need to store such a thing as the id in a hidden field in your view. That would mix your data with your user interface and create a lot of confusion and unnecessary view objects.

    If you are using a sqlite database to store your values you should use a CursorAdapter to manager your list items. The CursorAdapter stores the result that you got from the Database and manages how the data is displayed to the user. If you then register an onItemClickListener on your ListView the listener will receive the adapter and the position of the data item whose cell was clicked in the adapter. Now you can use getItem to retrieve a cursor pointing to the database result that was used to create the listitem. Now you can get the id or all other values that are not shown to the user from the database result and attach it to an intent to start the next activity.

提交回复
热议问题