2016-12-16 55 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

相關問題