vendredi 3 avril 2015

How do i correctly save CheckBox states using CursorAdapter?

This is my CursorAdapter class. I am getting the scrolling issues.Actually the checkboxes are loosing their states This is my CursorAdapter class.



public class TaskListAdapter extends CursorAdapter {

private Context context;
private TaskCursor tc;
ArrayList<Boolean> checkbox_arr = new ArrayList<Boolean>();
public TaskListAdapter(Context c, TaskCursor tc) {

super(c, tc, 0);
this.context = c;
this.tc = tc;
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Log.d("getViewTest", "new view");
//this.context=context;
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View row = li.inflate(R.layout.task_list_item, null, false);
return row;

}


@Override
public void bindView(View v, final Context context, Cursor c) {
Log.d("valuecheck","bindviewcalled");
final Task t = tc.getTask();
CheckBox cb = (CheckBox) v.findViewById(R.id.task_checkbox);
cb.setText(t.getName());
final long id =t.getId();
final Context ctx = context;
cb.setOnCheckedChangeListener(null);
if (t.getStatus()==0) {
cb.setChecked(false);
Log.d("valuecheck","Status value =0" );
} else {
cb.setChecked(true);
Log.d("valuecheck","Status value =1" );
}
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
t.updateStatus(1,context); // Update it in Database
Log.d("valuecheck","Setting " +t.getName()+ "to status 1" );

} else {
t.updateStatus(0,context);
Log.d("valuecheck","Setting " +t.getName()+ "to status 0" );
}
}
});

}
}


I have tried using saving states using an array but in vain.I have tried all the solutions but nothing worked.





Aucun commentaire:

Enregistrer un commentaire