2010-05-18 35 views
0

有沒有其他人有CheckedTextView顯示多個選中的項目時只有1檢查問題?當單擊CheckedTexView項目時,OnClickListener的響應是檢查點擊項目前後的條目。CheckedTextView表現不正常

下面的代碼:

mFriendDoneButton = (Button) findViewById(R.id.doneAddAFriendButton); 
    mListView = (ListView)findViewById(R.id.contactList); 

    populateContactList(); 

    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 
    mListView.setItemsCanFocus(false); 

    mListView.setOnItemClickListener(
      new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> adapterView, View view, 
       int arg2, long arg3) { 
      int selectedPosition = arg2; 

      CheckedTextView textView = (CheckedTextView)view.findViewById(R.id.friendEntryText); 
      String mtext = textView.getText().toString(); 


      Log.i("AddAFriendActivity", "Click on position "+selectedPosition); 

      Toast t = new Toast(AddAFriendActivity.this); 
      t = Toast.makeText(AddAFriendActivity.this, "Clicked on " + arg2+mtext+arg3, Toast.LENGTH_LONG); 
      t.show(); 

      } 
     }); 

私人無效populateContactList(){ //建立與聯繫人條目 光標光標= getContacts適配器(); String [] fields = new String [] { ContactsContract.Data.DISPLAY_NAME }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.friend_entry,cursor,fields,new int [] {R.id.friendEntryText}); mListView.setAdapter(adapter); }

private Cursor getContacts() 
{ 
    // Run query 
    Uri uri = ContactsContract.Contacts.CONTENT_URI; 

    String[] projection = new String[] { 
      ContactsContract.Contacts._ID, 
      ContactsContract.Contacts.DISPLAY_NAME 
    }; 
    String selection = null; 
    String[] selectionArgs = null; 
    String sortOrder = null; 

    return managedQuery(uri, projection, selection, selectionArgs, sortOrder); 
} 

的XML如下:

回答

0

發現了問題...的TextView需要被聲明爲一個字段,否則managedQuery結果循環通過onClickListener。