I am trying to define a Custom SimpleCursorAdapter Class, which will be used to populate the rows of a ListView. I am using the v4.widget.SimpleCursorAdapter library for backward compatibility. I am having issues with the following two parts of the code.
In the constructor, I am using
super(context,layout,c,from,to);
Meanwhile, this is deprecated, and I am not sure how to modify it.
Also, in
alarm_activated = (ToggleButton)row.findViewById(R.id.alarm_activated);
"row" cannot be resolved, and I am not sure how to reference the rows in question. (This syntax was working in a ArrayAdapter, and I was hoping that it would also work in a SimpleCursorAdapter...).
Perhaps, some other parts of my code (found hereafter) are incorrect.
class AlarmRowAdapter extends SimpleCursorAdapter {
private Context mContext;
private Context appContext;
private int layout;
private Cursor cr;
private final LayoutInflater inflater;
public AlarmRowAdapter(Context context,int layout, Cursor c,String[] from,int[] to) {
super(context,layout,c,from,to);
this.layout=layout;
this.mContext = context;
this.inflater=LayoutInflater.from(context);
this.cr=c;
}
@Override
public View newView (Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(layout, null);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
alarm_activated = (ToggleButton)row.findViewById(R.id.alarm_activated);
if (activationInt == 1) {
alarm_activated.setChecked(true);
alarm_activated.getBackground().setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY);
} else {
alarm_activated.setChecked(false);
}
alarm_activated.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
buttonView.getBackground().setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY);
} else {
buttonView.getBackground().setColorFilter(Color.LTGRAY, PorterDuff.Mode.MULTIPLY);
}
}
});
}
}