SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.contact_item, new String[] { "name" }, new int[] { R.id.name });
listView.setAdapter(adapter);
listView.setItemsCanFocus(false);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckedTextView checkedTextView = (CheckedTextView) view.findViewById(R.id.name);
checkedTextView.toggle();
System.out.println(checkedTextView.getText().toString());
}
});
当我单击ListView中的第一项时,CheckedTextView会选择ListView中的最后一项,并且System.out是正确的。我不知道为什么,我该如何解决?