简体   繁体   中英

How to get listview item click count in android?

我有一个带有一些数据的Listview。我想获取每个ListView项目的点击次数。基于点击数,我想重新排列Listview项目,请有人帮我一些代码

I'm no Java developer, but I doubt that by default such data are stored. Probalby, you should catch the item click event, store in some kind of array the id (index?) of the item and click count. Then, rearrange the list.

simplest answer :

add a new field to the database table you are retrieving the data from to hold the number of clicks an item have for example name it rank .

when you want to retrieve the data append the order by rank DESC to your query . this way your list will display the items by their rank ie (the top ranked item will be displayed at the top of the list and so on... )

and each time the user click an item increment the rank of that item by updating the rank field .

in case you want to reorder the list after each click use the cursor.requery() method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM