In my activity intially Position 0 item alone get checkmarked ,when i click it disappears.same way all items.but what i want is.only one item image should appaer if i click other item previous item image should disappear.
In getview() intially i took position 0 item as checkmarked.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> listView, View itemView, int position, long id) {
ImageView imageView = (ImageView) itemView.findViewById(R.id.img);
if (position ==0)
{
itemToggled[position] = ! itemToggled[position];
imageView.setImageResource(itemTogg开发者_如何学Pythonled[position] ? R.drawable.empty :R.drawable.checked);
}else{
itemToggled[position] = ! itemToggled[position];
imageView.setImageResource(itemToggled[position] ? R.drawable.checked : R.drawable.empty);
}
}
});
You basically need some data structure to keep track of checked items. you can use boolean array in your custom adapter.
the same question here Problem with checkbox
and also you can find some usefull links in the answer.
精彩评论