2016-12-16 53 views
-1

我需要帮助获取点击项目时点击多少次列表项目。请帮帮我。如果5月列表项被点击两次,我想拿到项目计数如何获得listview的数量项目被点击android

rightList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
       @Override 
       public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
        int len = rightList.getCount(); 
        item = data1.get(position); 
        int count = rightList.indexOfChild(view); 
        int cont=0; 
} 
+1

看到这一点:http://stackoverflow.com/questions/18030384/get-listview-item-clicked-count-in-android – rafsanahmad007

回答

0
// create a hashmap 

HashMap<Integer ,Integer> hasmap=new HashMap<Integer, Integer>(); 

//和列表视图onItemclick检查

if (hasmap.containsKey(_id)) 
    { 
     // increment the value if click on same listview item 

     int val = Integer.parseInt(hasmap.get(product_id)); 
     value = val + 1; 
     hasmap.put(_id, value); 
    } 
else 
{ 
    // 
    hasmap.put(_id, 1); 
} 
+0

是否有_id和product_id是新变量 –

+0

哪些值传递给_id和product_id请告诉我 –

+0

sry,这里_id和product_id是相同的。在我的情况下,我从JSON获取数据并将_id设置为listview.Here id是唯一编号,通过它我可以确定首次点击哪个行以及之前点击过哪个行。 – gautam

相关问题