Android ListView之选中(撤销选中)Item

时间:2024-09-25 13:37:02

在ContactListActivity中,点击未选中的item将其选中,再点击已选中的item撤销其选中

public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
    ContactListAdapter.ViewHolder viewHolder = null;
    if(mListAdapter.bShowCheckBox) {
        viewHolder = (ContactListAdapter.ViewHolder)view.getTag();
        TxrjContact contact = (TxrjContact)mListAdapter.getItem(position);
        contact.setSelected(!contact.isSelected());
        viewHolder.select
                .setImageBitmap(contact.isSelected() ? mListAdapter.checkBox
                        : mListAdapter.unCheckBox);
    }
}