I implemented multiple switches in CustomAdapter.
CustomAdapter code below.
sche_swt = (Switch)convertView.findViewById(R.id.ctschedule);
loc_swt = (Switch)convertView.findViewById(R.id.ctlocation);
sche_swt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean is_checked) {
if (compoundButton.getId() == R.id.ctschedule) {
if (is_checked == true) {
contactItemList.get(position).setSchedule(true);
} else {
contactItemList.get(position).setSchedule(false);
}
}
}
});
if (contactItemList.get(position).getScheduleInt() == 1) {
sche_swt.setChecked(true);
}
else
sche_swt.setChecked(false);
loc_swt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean is_checked) {
if (compoundButton.getId() == R.id.ctlocation) {
if (is_checked == true) {
contactItemList.get(position).setLocation(true);
}
else {
contactItemList.get(position).setLocation(false);
}
}
}
});
if (contactItemList.get(position).getLocationInt() == 1) {
loc_swt.setChecked(true);
}
else
loc_swt.setChecked(false);
return convertView;
}
One single line looks like
name
phone_number
switch 1 | switch 2
And I stored state of switches
For example :
1 line = switch(false) | switch(true)
2 line = switch(false) | switch(true)
3 line = switch(true) | switch(false)
... and so on.
After I finished my app, re-executed listview result looks like
1 line = switch(true) | switch(false)
2 line = switch(true) | switch(false)
3 line = switch(true) | switch(false)
What's wrong??