Bonsoir à tous, je suis novice sur android et je me heurte à un problème assez embêtant. Je réalise une application de commande de nourriture et je m'occupe de la partie modération des commentaire. Le problème vient des commentaires sur les commandes. Je récupère tous les commentaire depuis ma base de données sqlite puis je les affiche dans un scrollview. Le problème vient lorsque je valide le commentaire ou lorsque je le supprime. Mes deux requêtes ont en paramètre l'id de la commande mais je n'arrive pas a avoir l'id du commentaire sur lequel je clique, seulement le dernier qui s'affiche donc je supprime ou j'update constamment le dernier commentaire de la liste.
voici le code de l'activity en question:
Si vous pouviez m'expliquer comment récupérer le bon id ça m'aiderai beaucoup.
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 public class DetailsCommentaireRestoActivity extends Activity { private String idResto; private ArrayList<Evaluer> listeCommentaire; private String mail; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details_commentaire_resto); TextView txtCommentaire = (TextView) findViewById(R.id.txtCommentaire); LinearLayout layoutScroll = (LinearLayout) findViewById(R.id.layoutScroll); Intent intentReceived = getIntent(); if (intentReceived != null) { String idR = intentReceived.getStringExtra("idR"); Log.d("idR", "ID RECEIVED IN LISTE COMMENTAIRE: " + idR); idResto = idR; } EvaluerDAO commResto = new EvaluerDAO(this); listeCommentaire = commResto.getCommentairesByidR(idResto); if(listeCommentaire.size() == 0){ txtCommentaire.setText("aucun commentaire non traité pour ce restaurant"); } //txtCommentaire.setText(listeCommentaire.get(0).getCommentaire()); for (int i = 0; i < listeCommentaire.size(); i++) { LinearLayout Layout1 = new LinearLayout(this); Layout1.setOrientation(LinearLayout.VERTICAL); TextView txtComm = new TextView(this); txtComm.setText(listeCommentaire.get(i).getCommentaire()); Layout1.addView(txtComm); TextView txtNoteRecette = new TextView(this); txtNoteRecette.setText("respect de la recette :"+listeCommentaire.get(i).isRespectRecette()+"/5"); Layout1.addView(txtNoteRecette); TextView txtNoteEsteRepas = new TextView(this); txtNoteEsteRepas.setText("esthetique du repas :"+listeCommentaire.get(i).getEsthetiquePlat()+"/5"); Layout1.addView(txtNoteEsteRepas); TextView txtNoteCout = new TextView(this); txtNoteCout.setText("cout du repas :"+listeCommentaire.get(i).getCout()+"/5"); Layout1.addView(txtNoteCout); TextView txtNoteQualiteNourriture = new TextView(this); txtNoteQualiteNourriture.setText("qualité de la nourriture :" +listeCommentaire.get(i).getQualiteNourriture()+"/5"); Layout1.addView(txtNoteQualiteNourriture); final TextView txtMail = new TextView(this); txtMail.setText(listeCommentaire.get(i).getMailU()); Layout1.addView(txtMail); LinearLayout Layout2 = new LinearLayout(this); Layout2.setOrientation(LinearLayout.HORIZONTAL); Layout1.addView(Layout2); Button AcceptComm = new Button(this); AcceptComm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mail = (String) txtMail.getText(); AccepteComm(mail); } }); AcceptComm.setText("Valider"); Layout2.addView(AcceptComm); Button SupprComm = new Button(this); SupprComm.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { mail = (String) txtMail.getText(); SuppreComm(mail); } }); SupprComm.setText("Supprimer"); Layout2.addView(SupprComm); layoutScroll.addView(Layout1); } } public void AccepteComm(String mail){ EvaluerDAO evalAcces = new EvaluerDAO(this); evalAcces.updateCommVisible(idResto, mail); } public void SuppreComm(String mail) { EvaluerDAO evalAcces = new EvaluerDAO(this); evalAcces.deleteRComByIdrRMailu(idResto, mail); } }
J'espère que vous aurez le courage de tout lire, bonne soirée à tous
Partager