Ajouter des Event dans une liste de Checkbox
Bonjour,
J'ai affiché une liste de checkbox. On peut cliquer sur le bouton de checkbox mais comment faire pour générer un event lorsque on clique sur ce bouton ?
J ai utilisé le tuto de Notepad. POour afficher la liste de checkbox j utilise ce code (voici une partie du code complet ):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notes_list);
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
// Get all of the rows from the database and create the item list
notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.txvtask};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.task_list_item, notesCursor, from, to);
setListAdapter(notes);
} |
R.id.txvtask désigne un bouton checkbox. Avant il y avait un simple bouton et le bouton avait un event qui marchait avec onListItemClick. Cette event onListItemClick ne marche pas pour le bouton checkbox.
Comment faire pour corriger cela ?
Dans filldata j ai voulu ajouté le code suivant pour lancer un event lors du click de la checkbox. Malheureusement le code suivant ne marche pas :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
// Get all of the rows from the database and create the item list
notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.txvtask};
CheckBox repeatChkBx =
( CheckBox ) findViewById( R.id.txvtask );
repeatChkBx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
createNote();
}
});
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.task_list_item, notesCursor, from, to);
setListAdapter(notes);
} |
Merci