I am a beginner in Android, I have a ListView
which loads data from SQLite
database with this code on onCreate
:
Cursor cursor = dbAdapter.getAllTasks();
String[] fromFields = new String[] {dbAdapter.dbHelper.KEY_TASK};
int[] toView = new int[] {R.id.task};
SimpleCursorAdapter myCursorAdapter;
myCursorAdapter = new SimpleCursorAdapter(getBaseContext(), R.layout.task_items, cursor, fromFields, toView, 0);
ListView myList = (ListView) findViewById(R.id.taskList);
myList.setAdapter(myCursorAdapter);
I have db fields task (text), done (boolean) and date (text)
.
I can toggle strike through in the TextView on item click of ListView using this code and I can change the db field done
value here:
ListView myList = (ListView) findViewById(R.id.taskList);
myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView v = (TextView) view.findViewById(R.id.task);
if ((v.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) > 0){
v.setPaintFlags( v.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
} else {
v.setPaintFlags(v.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
// calling update method to change done value in db
}
});
Now how can I strike through all items which is marked as done (done = 1
) when loading ListView.
Aucun commentaire:
Enregistrer un commentaire