Get listview item clicked count in android

后端 未结 1 842
清歌不尽
清歌不尽 2021-01-28 21:29

I want to count the number of clicks of particular item in list view. Suppose there are 3 items in list view and I click 1st item for 1st time, it should display toast message t

相关标签:
1条回答
  • 2021-01-28 21:50

    Simply you can use Map<String, Integer> here to get the count for your ListView item. Just keep the default value as 0 in the Map and add 1 always inside the onItemClick() of ListView.

    Pseudo Code,

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                                                                        long arg3) {
        int count = 0;
        try {
            count = map.get(your_listview_value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        map.put(your_listview_value, (count + 1));
        Toast.makeText(getBaseContext(), 
                                 String.valueOf(count), Toast.LENGTH_LONG).show();
    }
    
    0 讨论(0)
提交回复
热议问题