lundi 23 mars 2015

Checkbox in a custom adapter to update the database

I am trying to get the checkbox I created in a custom adapter for a list to update the database upon clicking on it. I implemented the onclicklistener on the checkbox inside the customAdapter (code below). I also added a Toast to check if it works. The problem is that the Toast displays the right information for each row (the name of the item i click on); however the database doesn't get updated.



datasource = new MySQLiteHelper((AssTasksActivity) context);

CB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Task Ta = task; //Task is an object with a separate class that is stored in the sqlite db.

if(CB.isChecked()){
Ta.setState(0);
datasource.updateTask(Ta);
//Toast T;
Toast.makeText(context, Ta.getTaskName(),
Toast.LENGTH_LONG).show();
}
else{

Ta.setState(1);
datasource.updateTask(Ta);
Toast.makeText(context, Ta.getTaskName(),
Toast.LENGTH_LONG).show();
}
}
});




Aucun commentaire:

Enregistrer un commentaire