2013-08-28 2 views
0

사용자 정의 된 목록보기에서 선택한 행의 총 수를 찾으려고합니다. 항목 수 (행)가 2 이상이면 목록보기를 다시 클릭 할 수 없습니다. 여기서는 사용자 지정 검사 목록 (복수 선택)을 사용하고 있습니다.listview 선택한 행의 개수보기

+0

을 시도하는 것 : 요소는 Map 반복을 체크? 몇 가지 코드를 게시하십시오. – 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 방법은 전화를받을 오버라이드 (override) 할 때 HashMap에 체크 박스와 (내 예를에 TextView을 사용했습니다 ) 행에 표시된 다른 요소를 저장하기 위해 노력하고 얼마나 많은 셀 수 당신이

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;