0

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(itemToggled[position] ?  R.drawable.empty :R.drawable.checked);

              }else{
                       itemToggled[position] = ! itemToggled[position];
                 imageView.setImageResource(itemToggled[position] ? R.drawable.checked : R.drawable.empty);

              }
        }
    });
Rahul Choudhary
  • 3,789
  • 2
  • 30
  • 30
user828948
  • 151
  • 1
  • 3
  • 8

1 Answers1

0

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.

Community
  • 1
  • 1
bHaRaTh
  • 3,464
  • 4
  • 34
  • 32