2012-09-01 158 views
0

我一直在閱讀過去幾個小時的教程和論壇帖子,試圖獲得一個簡單的複選框listview實現。我知道(我相信)我需要如何保持列表中的複選框的狀態(o在我的情況下是地圖)。ListView和複選框 - 複選框沒有在教程中打勾

這是這樣一個簡單的事情,我敢肯定,但我的複選框沒有被設置爲true或false在我的bindView方法。這裏是代碼

public void bindView(View view, Context context, Cursor cursor) { 
     final int rowId = cursor.getInt(cursor.getColumnIndexOrThrow("_id")); 

     familyText = (TextView)view.findViewById(R.id.contacts_row_family_name); 
     markedBox = (CheckBox)view.findViewById(R.id.contacts_row_check); 
     familyText.setText(cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME))); 



     view.setOnClickListener(new OnClickListener(){ 

      public void onClick(View arg0) { 
       Log.d("OnClick","Row clicked"); 
       boolean currentlyChecked; 

       if(checkedState.size() >= rowId){ 
        currentlyChecked = checkedState.get(rowId); 
        checkedState.put(rowId, !currentlyChecked); 
       }else{ 
        currentlyChecked = false; 
        checkedState.put(rowId, !currentlyChecked); 
       } 

       markedBox.setChecked(checkedState.get(rowId)); 

      } 

     }); 

     setProgressBarIndeterminateVisibility(false); 


    } 

這裏是checkedState的聲明。這是我的活動的類成員。

private Map<Integer, Boolean> checkedState = new HashMap<Integer,Boolean>(); 

據我所知,我應該有一個監聽器(這是因爲我的日誌消息打印正確),但複選框不會改變。

回答

0

更新:

我錯了,我的複選框沒有被檢查。只是錯誤的被檢查。我將結束這個問題。