Check box checked Automatically in listview when scrolling the list.
I have one problem, i have customize listview
with checkbox
.
When i s开发者_开发知识库croll the items the some checkbox
is automatically checked
without clicking on checkbox
.
Can any one help me?
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;
}
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.
精彩评论