I have two problems:
What am I trying to achieve is a listview with switch button in each row and it's working fine, but I want to set on start 4th and 5th switch on True
holder.s.setChecked(possition==4);
holder.s.setChecked(possition==5);
setting on true only the 5th, how to do this, give me any hint?
Second problem: While scrolling my listview changing state of switch buttons, I've tried many many tutorials but with no luck, how to keep state of switch buttons?
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
String pytanie = getItem(position);
if (convertView==null){
convertView = inflater.inflate(R.layout.cardio_row, null);
holder = new ViewHolder();
holder.question = (TextView) convertView.findViewById(R.id.question);
holder.s = (Switch)convertView.findViewById(R.id.switch1);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
//Model_cardio question = getItem(position);
holder.question.setText(pytanie);
holder.s.setChecked(position == 4);
holder.s.setChecked(position == 5);
holder.s.setTag(position);
return convertView;
}
EDIT: I've added this, and want to store a state in some list
holder.s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});