Bonjour,

J'ai une listview qui me permet de faire 2 actions :

.cliquer sur une ligne et m'envoyer sur une autre activity,
.cliquer sur un radio button pour sélectionner cette ligne et la supprimer par un button.

Mon premier souci, c'est que je peut sélectionner plusieurs radioButton et mon second c'est que je n'arrive pas a supprimer une ligne par l'intermédiaire d'un bouton.

Voici mon 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     >
 
    <RadioButton
        android:id="@+id/RbtnSelect"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:layout_gravity="center_vertical"
	   	android:padding="10dp"
	   	android:focusable="false"
	   	android:onClick="onClickRadioButton" 
	   	android:layout_marginLeft="10dp"
        android:text="@string/RbtnSelect" />
 
    <LinearLayout 
	    android:orientation="vertical"
	    android:layout_width="0dip"
	    android:layout_height="wrap_content"
	   	android:layout_gravity="center_vertical"
	   	android:paddingLeft="10dp"
	    android:layout_weight="1"
	    >
 
    <TextView
        android:id="@+id/TvBank"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="@string/bank" />
 
    <TextView
        android:id="@+id/TvNom"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textStyle="bold"
        android:text="@string/nom" />
 
  </LinearLayout>
 
    <TextView
        android:id="@+id/TvMontant"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:layout_gravity="right"
        android:layout_marginRight="15dp"
        android:gravity="right"
	   	android:padding="10dp"
        android:text="@string/montant" />
 
    <ImageView 
        android:id="@+id/ImgFleche"
        android:layout_height="59dip" 
        android:layout_width="59dip" 
        android:src="@drawable/fleche"
        android:layout_gravity="center_vertical"
	   	android:padding="10dp"
        android:contentDescription="@string/fleche" 
></ImageView>
</LinearLayout>
Mon activity
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
122
123
124
125
126
127
128
129
130
131
132
 
public class LesComptes extends ListActivity {
 
	private Compte[] compte_read;
    private ArrayAdapter<Compte> listAdapter;
 
	private Button BtnAjout;
	private Button BtnSup;
	private Button BtnApercu;
	private ListView LvCompte;
	private DBAdapter db;
	private Cursor cursor;
	private int idUtilisateur;
	private int idCompte;
	private Utilisateur utilisateur;
	private Compte compte;
	private Bundle bundle;
 
 
	 final Context context = this;
	//constante pour les alertDial
			private final static int ID_NOT_SELECT = 0;
			private final static int ID_NOT_COMPTE = 1;
	public Utilisateur getUtilisateur(){
		return utilisateur;
	}
	public void setUtilisateur(Utilisateur utilisateur){
		this.utilisateur = utilisateur;
	}
 
	public Compte getCompte(){
		return compte;
	}
	public void setCompte(Compte compte){
		this.compte = compte;
	}
 
 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.les_comptes);
 
 
		BtnAjout = (Button)findViewById(R.id.BtnAjout);
		BtnSup = (Button)findViewById(R.id.BtnSup);
		BtnApercu = (Button)findViewById(R.id.BtnApercu);
		LvCompte = (ListView)findViewById(android.R.id.list);
		db = new DBAdapter(getApplicationContext());
		db.open();
		bundle = this.getIntent().getExtras();
		utilisateur = new Utilisateur();	
	    compte = new Compte();
 
	    TestAdapter();
	    AddListenerOnBtnAjout();
 
	    //ListView();
	    //onClickRbtnSelect();
	   // AddListenerOnBtnApercu();
	    //AddListenerOnBtnSupprimer();
 
	}
 
	public void TestAdapter(){
		//On récupère les données du Bundle
    	idUtilisateur = (Integer) bundle.get("COL_ID");
 
        	    // Find the ListView resource.
        	    LvCompte = (ListView) findViewById(android.R.id.list);
 
        	    LvCompte
        	            .setOnItemClickListener(new AdapterView.OnItemClickListener() {
        	                @Override
        	                public void onItemClick(AdapterView<?> parent, View item,
        	                        int position, long id) {
        	                	compte.setIdCompte((int)id);
 
        	                	//méthode pour la liste des transactions
        	    				//id du compte dans le bundle
        	    				bundle.putInt("Id_compte",compte.getIdCompte());
        	    				Intent intent = new Intent(LesComptes.this, LesTransactions.class);
        	    				intent.putExtras(bundle);
        	    				startActivity(intent);
 
        	                    Compte compte = listAdapter.getItem(position);
        	                    compte.toggleChecked();
        	                    CompteViewHolder viewHolder = (CompteViewHolder) item
        	                            .getTag();
        	                    viewHolder.getRbtnSelect().setChecked(compte.isChecked());
        	                }
        	            });
 
        	    // Throw Query and fetch the contacts.
 
        	  //selectionne liste de compte de l'utilisateur
            	cursor = db.SelectDesComptesUtilisateur(idUtilisateur);
 
        	    if (cursor != null && cursor.getCount() != 0) {
        	        cursor.moveToFirst();
 
        	        compte_read = new Compte[cursor.getCount()];
 
        	        // Add Compte to the Array
 
        	        int j = 0;
        	        do {
 
        	            compte_read[j] = new Compte(cursor.getString(cursor
        	                    .getColumnIndex("COL_BANK")),cursor.getString(cursor.getColumnIndex("COL_TITRE")),cursor.getDouble(cursor.getColumnIndex("COL_TOTAL")));
 
        	            j++;
        	        } while (cursor.moveToNext());
 
        	     // Add Compte Class to the Arraylist
 
            	    ArrayList<Compte> compteList = new ArrayList<Compte>();
            	    compteList.addAll(Arrays.asList(compte_read));
 
            	    // Set our custom array adapter as the ListView's adapter.
            	    listAdapter = new CompteArrayAdapter(this, compteList);
 
            	    LvCompte.setAdapter(listAdapter);
            	    LvCompte.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
 
        	    } else {
 
                    BtnApercu.setEnabled(false);
                    BtnSup.setEnabled(false);
                    showDialog(ID_NOT_COMPTE);
        	    } 
 
        	    }
et mon custom adaptater
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
 
public class CompteArrayAdapter extends ArrayAdapter<Compte> {
 
	    private LayoutInflater inflater;
	    private int selected = -1;
 
	    public CompteArrayAdapter(Context context, List<Compte> compteList) {
	        super(context, R.layout.listeview_compte, R.id.TvBank, compteList);
	        // Cache the LayoutInflate to avoid asking for a new one each time.
	        inflater = LayoutInflater.from(context);
 
	    }
 
	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        // Contact to display
	        Compte planet = (Compte) this.getItem(position);
	        System.out.println(String.valueOf(position));
 
	        // The child views in each row.
	        RadioButton RbtnSelect;
	        TextView TvBank;
	        TextView TvNom;
	        TextView TvMontant;
	        // Create a new row view
	        if (convertView == null) {
	            convertView = inflater.inflate(R.layout.listeview_compte, null);
 
	            // Find the child views.
	            TvBank = (TextView) convertView
	                    .findViewById(R.id.TvBank);
	            RbtnSelect = (RadioButton) convertView.findViewById(R.id.RbtnSelect);
                TvNom = (TextView) convertView.findViewById(R.id.TvNom);
                TvMontant = (TextView) convertView.findViewById(R.id.TvMontant);
	            // Optimization: Tag the row with it's child views, so we don't
	            // have to
	            // call findViewById() later when we reuse the row.
	            convertView.setTag(new CompteViewHolder(RbtnSelect, TvBank, TvNom,TvMontant, null));
 
	            // If CheckBox is toggled, update the Contact it is tagged with.
	            RbtnSelect.setOnClickListener(new View.OnClickListener() {
	                public void onClick(View v) {
 
	                    RadioButton rb = (RadioButton) v;
	                    Compte compte = (Compte) rb.getTag();
	                    compte.setChecked(rb.isChecked());
	                }
	            });
	        }
	        // Reuse existing row view
	        else {
	            // Because we use a ViewHolder, we avoid having to call
	            // findViewById().
	            CompteViewHolder viewHolder = (CompteViewHolder) convertView
	                    .getTag();
	            RbtnSelect = viewHolder.getRbtnSelect();
	            TvBank = viewHolder.getTvBank();
	            TvNom = viewHolder.getTvNom();
	            TvMontant = viewHolder.getTvMontant();
	        }
 
	        // Tag the RadioButton with the Compte it is displaying, so that we
	        // can
	        // access the Compte in onClick() when the RadioButton is toggled.
	        RbtnSelect.setTag(planet);
 
	        // Display Contact data
	        RbtnSelect.setChecked(planet.isChecked());
	        TvBank.setText(planet.getBank());
	        TvNom.setText(planet.getTitre());
	        TvMontant.setText(String.valueOf(planet.getTotal()));
 
	        return convertView;
	    }
 
}
merci pour votre aide.