2012-12-06 73 views
1

我正在嘗試製作具有多項選擇的聯繫人選擇器。我可以使用旁邊的複選框加載所有聯繫人。但是,當我選擇一個項目時,每個第8個項目都會在我的列表中自動選擇。而且,當我上下滾動時,所有選擇都會自行更改。在多選列表視圖中選擇一個項目會選擇多個項目

有人知道這有什麼問題嗎?這是我的聯繫人選擇器類

public class HomeActivity extends ListActivity { 

    public void onCreate(Bundle paramBundle) { 
     super.onCreate(paramBundle); 

     Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null); 
     SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
       android.R.layout.simple_list_item_multiple_choice, 
       cursor, 
       new String[] {ContactsContract.Contacts.DISPLAY_NAME}, 
       new int[] { android.R.id.text1},0); 

     setListAdapter(adapter);  
    } 

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) {   
     CheckedTextView textView = (CheckedTextView)v; 
     textView.setChecked(!textView.isChecked()); 
    } 
} 

回答

2

它發生的,因爲回收機制在ListView的意見。嘗試在您的onCreate()中添加以下內容。

getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);