Bonjour à tous.

C'est mon premier post ici. J'espère n'avoir pas fait de bêtises (oubli ou autre).
Je vous explique mon soucis.

J'ai creer un programme qui affiche dans une listview ce qui est contenu en base de donnée Sqlite. J'ai une action bar avec dans un menu un bouton qui doit supprimer toutes les entrées marquées par une checkbox coché.

Pour celà, à l'appui du bouton, je parcours ma liste et je doit faire un test sur chaque checkbox. Problème, comment récupérer ce checkbox... je ne peux pas mettre un bête findViewById, puisqu'il n'est pas dans le même xml que celui déclarer par setContentView();

Je vous met en code un version allégé de l'appli. Si vous pourriez me donner un coup de main. J'ai pas mal chercher, apparemment il faut modifier le simpleCursorAdapter pour avoir un getView spécifique.

Je suis un peu perdu. La panne se situe dans le switch case, j'ai essayé plusieurs choses. Je laisse mes erreurs en commentaires.

Voici mon code
main.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
</LinearLayout>
list_row.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"
    android:descendantFocusability="blocksDescendants" >  
 
    <LinearLayout 
    android:id="@+id/linearLayout"  
	 android:layout_width="wrap_content"
	android:layout_height="fill_parent"
	 android:layout_alignParentLeft="true"
	 android:layout_alignParentTop="true">
 
     <CheckBox 
				android:id="@+id/check"
				android:layout_marginLeft="10dp"
				android:layout_marginTop="20dp"
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content" />
     </LinearLayout>
 
     <LinearLayout
         android:id="@+id/linearLayout1"
         android:layout_width="wrap_content"
         android:layout_height="fill_parent"
         android:layout_alignParentRight="true"
         android:layout_alignParentTop="true"
         android:layout_toRightOf="@+id/linearLayout" >
 
   <TextView
       android:id="@+id/text1"
       android:layout_width="291dp"
       android:layout_height="70dp"
       android:padding="18dp"     
       android:textSize="35sp"
       android:textColor="#4F4F4F" />  
 
	<TextView
    android:id="@+id/text2"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:textSize="25sp"
     />
 
	</LinearLayout>
</RelativeLayout>
note_list.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
    	android:layout_height="wrap_content">
 
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"       
        android:listSelector="@drawable/list_selector_flatcolor"
        android:dividerHeight="1dp"
        android:choiceMode="multipleChoice"
         />
 
  	<TextView android:id="@+id/android:empty"
          android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:text="@string/no_notes"
        	android:textSize="30sp"
        	android:layout_marginLeft="100dp"
        	android:layout_marginTop="100dp"/>
</LinearLayout>
Main.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notes_list);
        mDbHelper = new NotesDbAdapter(this);
        mDbHelper.open();
        fillData();
 
    }
 
    private void fillData() {
 
        Cursor notesCursor = mDbHelper.fetchAllNotes();
        startManagingCursor(notesCursor);
 
        String[] from = new String[]{NotesDbAdapter.KEY_ND, NotesDbAdapter.KEY_NOM };
 
        int[] to = new int[]{R.id.text1, R.id.text2};
        notes = new CheckboxAdapter(this, R.layout.notes_row, notesCursor, from, to);
        setListAdapter(notes);
 
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);        
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menucourt, menu);
 
 
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
            case R.id.add:
               createNote();
                return true;          
            case R.id.suppsel:
            	 ListView lv = getListView();
            	 for(int i=0; i<=lv.getCount(); i++){   
            		 //View v= lv.getChildAt(i);
            		 //CheckBox cbx = (CheckBox)v.findViewById(R.id.check);
                     /*if(cbx.isChecked()){
                    	 System.out.println("Oui");
                    }*/
            		 //System.out.println(lv.getAdapter().getItem(i));
            		 //mDbHelper.deleteNote(lv.getItemIdAtPosition(i)); pour supprimé l'entrée à chaque tour         		 
            		 //System.out.println(notes.stateCheck(i));
            			 //System.out.println("Oui");
            	 }
                 /*int position1 = lv.getPositionForView(v);
                 System.out.println(position1);
                 CheckBox cd = (CheckBox) v.findViewById(R.id.check);
                 if(cd.isChecked())
                 		System.out.println("yes");*/
            	return true;
        }
 
        return super.onOptionsItemSelected(item);
    }
 
 
 
 
 
            case DELETE_ID:
                AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
                System.out.println(info.id);
                mDbHelper.deleteNote(info.id);
                fillData();
                return true;
            case delete_all:
            	alertDialog = new AlertDialog.Builder(Notepadv3.this).create();
            	alertDialog.setTitle("Confirmation suppression");
            	alertDialog.setMessage("Etes vous sur(e) de vouloir tout supprimer?");
            	alertDialog.setButton("Annuler", new DialogInterface.OnClickListener() 
            	{
            		public void onClick(DialogInterface dialog, int which) 
            		{
            			alertDialog.dismiss(); 	                 	 
            	    } 
            	});
            	alertDialog.setButton2("Valider", new DialogInterface.OnClickListener() 
            	{
            		public void onClick(DialogInterface dialog, int which) 
            		{          	    	 
            	    	mDbHelper.delete_all();
                        fillData(); 
            	    } 
            	});
 
            	 alertDialog.show(); 
 
        }
        return super.onContextItemSelected(item);
    }
 
    private void createNote() {
        Intent i = new Intent(this, creationbox.class);
        startActivity(i);        
    }
 
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Intent i = new Intent(this, NoteEdit.class);
        i.putExtra(NotesDbAdapter.KEY_ROWID, id);
        startActivityForResult(i, ACTIVITY);
 
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        fillData();
    }
 
}
Je suis curieux de savoir ou est mon erreur et comment la résoudre. Je pense à un soucis de View...
Merci d'avance.