Bonjour,
J'ai un problème avec la fonction findViewById qui me renvoie null. Voici mon code dans la fonction calcul(). Cette fonction est appelée sur le click sur une checkbox dans le onCreate. Le tableau tab1 est construit dans le onCreate.
Voici mon code :
Merci pour votre aideCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public void calcul(){ double montants = 0; for(int i = 0; i <tab1.getChildCount();i++){ View view = tab1.getChildAt(i); EditText montant = (EditText) view.findViewById(R.id.row_montant); try{ montants+= Double.parseDouble(montant.getText().toString()); }catch (NumberFormatException e){ AlertDialog.Builder builder = new AlertDialog.Builder(this.getParent()); String error = "Ce montant doit être un nombre"; builder.setTitle("Erreur"); builder.setMessage(error).setCancelable(true).setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); montant.setText(""); return; } } }