Ok, I have a holder, holding a bunch of elements that won't change except for the switch (obviously).
I reduced the code, for it to be simpler to read, I thought this would allow me to see in the logs the state being changed of the switches (which are generated dynamically from the adapter).
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
holder = new ViewHolder();
holder.communicationfilter = (Switch)convertView.findViewById(R.id.communicationfilter);
holder.communicationfilter.setChecked(!kid.isBlocked());
holder.communicationfilter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.v(LOG_TAG, "Switch State="+isChecked);
}
});
convertView.setTag(holder);
return convertView;
}
This solved it, hope it helps someone having the same issue I had.
holder.communicationfilter.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
Toast.makeText(mContext, "The switch is ON",Toast.LENGTH_SHORT).show();
Log.i(LOG_TAG,"switch checked for" + holder.nameTxtView);
} else {
Toast.makeText(mContext,"The switch is OFF", Toast.LENGTH_SHORT).show();
Log.i(LOG_TAG,"switch unchecked" + holder.nameTxtView);
}
}
});