2013-08-28 23 views
0

我試圖找出自定義列表視圖中選定行的總數。如果項數(行數)超過2,則我們無法再次單擊列表視圖。在此處我正在使用自定義清單(多項選擇)列表查看所選行的計數編號

+0

什麼你試過嗎?發佈一些代碼。 – Avijit

+0

檢查此問題http://stackoverflow.com/questions/17698596/checkable-relative-layout-as-item-in-multiselect-list/17698673#17698673 – Raghunandan

回答

1
  lvMain.setOnItemClickListener(new OnItemClickListener() { 

    @Override 
    public void onItemClick(AdapterView<?> parent, final View view, int position, long id) 
     { 
     int len = lvMain.getCount(); 
     SparseBooleanArray checked = lvMain.getCheckedItemPositions(); 
     for (int i = 1; i < len; i++){ 
     if (checked.get(i)) { 
      count++; 


       /* do whatever you want with the checked item */ 
      } 

     } 
     if(count>2) 
     { 
      /* do whatever you want with the checked item count more than one x value*/ 
      lvMain.setSelected(false); 
      count=1; 
     } 
    }  

}); 
1

有什麼問題listView.getCheckedItemCount()

0

我想你正在嘗試計算多個listView中選定行的總數。

for(i=0; listCount; i++) { 
    if(mListView.isItemChecked(i)){ 

    } 
    else { 

    } 
} 
0

否則,你可以嘗試重寫時,getView方法被調用到您的複選框,並在一排顯示的其他元素(我已經在我的例子使用TextView)存儲在HashMap再算多少元素被檢查過Map迭代:

Iterator<Entry<TextView, CheckBox>> it = listCheck.entrySet().iterator(); 
    int i = 0; 
    while (it.hasNext()) { 
     Entry<TextView, CheckBox> entry = it.next(); 
     if (entry.getValue().isChecked()) 
       i++; 
    } 
    return i;