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());
    }   
}
4

1 回答 1

2

发生这种情况是因为ListView. 尝试在您中添加以下内容onCreate()

getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
于 2012-12-06T19:53:48.667 回答