获取Android中列表视图项点击数 [英] Get listview item clicked count in android

查看:113
本文介绍了获取Android中列表视图项点击数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要计数列表视图特定项目的点击次数。假设有列表视图中的3项和我点击第一个项目为1的时候,它应该显示敬酒消息,第一个项目点击数为1。现在,如果我再次点击第一个项目,信息应该是第一个项目点击数为2等其他项目。我怎样才能做到这一点?

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 that 1st item clicked count is "1". Now, if I again click 1st item, message should be 1st item clicked count is "2" and so on for other items. How can I do this?

推荐答案

只要您可以使用地图<字符串,整数> 这里得到您的ListView项计数。只要保持默认值0的地图和随时添加1中的 onItemClick()的ListView。

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.

伪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();
}

这篇关于获取Android中列表视图项点击数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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