I have a recyclerview with some items and checkbox include. I know, that can`t use boolean type in sqlite, so Iuse INTEGER (true = 1, false = 0). By default - false. When i tick on checkbox , I want to insert '1', else '0'.
My model class
public class Task {
private long mId;
private String mTitle;
private String mDesc;
private String mDate;
private String mSolved;
private String mTime;
//getters and setters... }
holder
public class TaskHolder extends RecyclerView.ViewHolder{
@BindView(R.id.tvTitle)
TextView title;
@BindView(R.id.tvDesc)
TextView desc;
@BindView(R.id.tvDate)
TextView date;
@BindView(R.id.tvTime)
TextView time;
@BindView(R.id.cbIsSolved)
CheckBox isSolved;
public TaskHolder(View itemView) {
super(itemView);
ButterKnife.bind(this,itemView);
}
public void bindTaskHolder(final Task task){
title.setText(task.getmTitle());
date.setText(task.getmDate());
time.setText(task.getmTime());
desc.setText(task.getmDesc());
isSolved.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean checked) {
// TODO Auto-generated method stub
if(checked)
{
task.setmSolved("1");
}
else
{
task.setmSolved("0");
}
}
});
}
}
and myadapter
public class TaskAdapter extends RecyclerViewTaskCursorAdapter<TaskHolder> {
public TaskAdapter(Context context, Cursor cursor) {
super(context, cursor);
}
@Override
public TaskHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tasklist, parent, false);
return new TaskHolder(view);
}
@Override
public void onBindViewHolder(TaskHolder viewHolder, Cursor cursor) {
long id = cursor.getLong(cursor.getColumnIndex(DatabaseHelper.ID_TASK));
String title = cursor.getString(cursor.getColumnIndex(DatabaseHelper.TITLE_TASK));
String desc = cursor.getString(cursor.getColumnIndex(DatabaseHelper.DESCRIPTION_TASK));
String date = cursor.getString(cursor.getColumnIndex(DatabaseHelper.DATE_TASK));
String time = cursor.getString(cursor.getColumnIndex(DatabaseHelper.TIME_TASK));
String solved = (cursor.getString(cursor.getColumnIndex(DatabaseHelper.IS_SOLVED_TASK)));
Task task = new Task();
task.setmId(id);
task.setmTitle(title);
task.setmDesc(desc);
task.setmDate(date);
task.setmTime(time);
task.setmSolved(solved);
viewHolder.bindTaskHolder(task);
}
}
thank in advince
Aucun commentaire:
Enregistrer un commentaire