开发者

when i click an item than item image alone should appear and unselected listitem's image should disappear

开发者 https://www.devze.com 2023-04-09 05:48 出处:网络
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 im

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消