0

I have one problem, i have customize listview with checkbox.

When i scroll the items the some checkbox is automatically checked without clicking on checkbox.

Can any one help me?

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
Yog Guru
  • 2,074
  • 3
  • 28
  • 47

2 Answers2

0

It means that ou select one checkbox and android will select randomly for that you should use...

if(tempVector.get(position)){
            holder.box.setChecked(true);
        }
        else{
            holder.box.setChecked(false);
        }

Try this, it works for me.

Bruno
  • 119,590
  • 31
  • 270
  • 376
Siten
  • 4,515
  • 9
  • 39
  • 64
  • in my scenario...for(int i=0; i < ImageDisplay.newimagelist; i++){ tempVector.set(i, true); } and after this onchacked change i will set the value of true and other are false. but after that also problem is still there so at end of chackedchangedlisner i put this.... – Siten Jul 29 '11 at 10:13
  • yes dude. if another user will face this issue and he will see this question then he could got right answer..i hope you can understand.. – Niranj Patel Jul 29 '11 at 10:24
  • @CapDroid but it is understood that some vector are there in that we put our checkbox at the size of list. – Siten Jul 29 '11 at 10:26
0

works fine for me

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        final Season season = (Season) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.season, parent, false);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.season_title);
            holder.checkBox = (CheckBox) convertView.findViewById(R.id.season_check_box);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(season.getTitle());
        holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                season.setChecked(isChecked);
                adapter.notifyDataSetChanged();
            }
        });

        holder.checkBox.setChecked(season.isChecked()); // position is important! Must be before return statement!
        return convertView;
    }

    protected class ViewHolder {
        protected TextView title;
        protected CheckBox checkBox;
    }
Georgy Gobozov
  • 13,633
  • 8
  • 72
  • 78
  • Anybody who needs an explanation of this code should watch [Android Google IO 2009 UI performance](http://www.youtube.com/watch?v=N6YdwzAvwOA) – Moog Sep 13 '11 at 16:48