Bonjour à tous,

Débutante en Java je rencontre un souci pour la création de ma première application,

Je souhaiterais afficher le résultat d'une requête SQL dans un tableau (donc dans un TableRow lui même dans un TableLayout d'après ce que j'ai compris), pour l'instant nous arrivons bien à afficher le résultat de la requête mais uniquement dans un TextView.

Ma question principale étant est ce que je dois tout créer en TableRow dès que je récupère les résultats de ma requête ou est ce que je peux transformer le résultat en ListView que j'ai déjà en TableRow? Après plusieurs recherches sur internet je n'arrive pas à résoudre mon problème.

En sachant que le but final est d'avoir, par exemple pour les Jupes, un tableau à 5 colonnes: Type, Ref, Couleur, Taille, et un checkbutton pour chaque Jupe. Comme un dessin vaut mieux que des mots:

Voici le code de l'activité:

(On récupère l'id_client pour afficher les valeurs qui lui correspondent venant de nos 3 tables (Jupe, Accessoire, Tshirt))

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
 
public class Wl extends AppCompatActivity {
        private int id_recherche;
        private TextView Wl_view;
        private DataBaseManager dataBaseManager;
 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_wl);
                id_recherche=getIntent().getIntExtra("id_client",0);
 
                Wl_view = (TextView) findViewById(R.id.Wl_view);
                dataBaseManager = new DataBaseManager(this);
 
                List<Client_WL_Jupe> WLj = dataBaseManager.ReadWLJupe(id_recherche);
                for (Client_WL_Jupe List : WLj ){
                        Wl_view.append(List.toString() + "\n\n");
                }
 
                List<Client_WL_Accessoire> WLa = dataBaseManager.ReadWLAccessoire(id_recherche);
                for (Client_WL_Accessoire List : WLa ){
                        Wl_view.append(List.toString() + "\n\n");
                }
 
                List<Client_WL_Tshirt> WLt = dataBaseManager.ReadWLTshirt(id_recherche);
                for (Client_WL_Tshirt List : WLt ){
                        Wl_view.append(List.toString() + "\n\n");
                }
            }
}
En sachant que nos Client_Wl_... sont formés de cette façon:

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
 
public class Client_WL_Jupe {
        private String JType;
        private String JRef;
        private String JCouleur;
        private String JTaille;
 
        public Client_WL_Jupe(String JType,String JRef, String JCouleur, String JTaille){
                this.setJType(JType);
                this.setJRef(JRef);
                this.setJCouleur(JCouleur);
                this.setJTaille(JTaille);
        }
 
        public String getJType() {return JType;}
        public void setJType(String JType) {this.JType = JType;}
        public String getJRef() {return JRef;}
        public void setJRef(String JRef) {this.JRef = JRef;}
        public String getJCouleur() {return JCouleur;}
        public void setJCouleur(String JCouleur) {this.JCouleur = JCouleur;}
        public String getJTaille() {return JTaille;}
        public void setJTaille(String JTaille) {this.JTaille = JTaille;}
 
        @Override
        public String toString() {
                return JType + JRef + JCouleur + JTaille;
        }
}
Et que la DataBaseManager contient

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
 
public class DataBaseManager extends SQLiteOpenHelper {
        private static final String DATABASE_NAME = "wishlist.db";
        private static final int DATABASE_VERSION = 2;
 
        public DataBaseManager(Context context) {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
 
        @Override
        public void onCreate(SQLiteDatabase db) {
                String strSql = "create table Jupe ("+" Id integer primary key autoincrement, "+" Type_ text not null, "+" Ref_ text not null, "+" Couleur text not null, "+" Taille text not null, "+" Coche integer not null "+")";
 
                db.execSQL(strSql);
 
                strSql = "create table Accessoire ("+ " Id integer primary key autoincrement, "+ " Type_ text not null, "+ " Couleur text not null, "+ " Motif text not null, "+ " Coche integer not null "+ ")";
                db.execSQL(strSql);
 
                strSql = "create table Tshirt ("+ " Id integer primary key autoincrement, "+ " Annee text not null, "+ " Couleur text not null, "+ " Taille text not null, "+ " Coche integer not null "+ ")";
                db.execSQL(strSql);
 
                strSql = "create table Affiliation ("+ " Id_produit integer, "+ " Id_client integer not null, "+ " Type text not null "+ ")";
                db.execSQL(strSql);
 
                strSql = "create table Client ("+ " Id_client integer primary key autoincrement, "+ " Nom text not null, "+ " Prenom text not null, "+ " Mail text not null, "+ " Password text not null, "+ " Morpho text not null "+ ")";
                db.execSQL(strSql);
 
                Log.i("DATABASE", "OnCreate invoked");
        }
 
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                String strSQL = "drop table Jupe";
                db.execSQL(strSQL);
                this.onCreate(db);
                Log.i("DATABASE", "Onupgrade invoked");
        }
 
        public void insertJupe(String type_, String ref_, String couleur, String taille, int coche) {
                String strSql = "insert into Jupe (Type_, Ref_, Couleur, Taille, Coche) values ('"+ type_ + "',' " + ref_ + "','" + couleur + "','" + taille + "'," + coche + ")";
                this.getWritableDatabase().execSQL(strSql);
                Log.i("DATABASE", "Jupe insert invoked");
        }
 
        public void insertAccessoire(String type_, String couleur, String motif, int coche) {
                String strSql = "insert into Accessoire (Type_, Couleur, Motif, Coche) values ('" + type_ + "','" + couleur + "','" + motif + "'," + coche + ")";
                this.getWritableDatabase().execSQL(strSql);
                Log.i("DATABASE", "Accessoire insert invoked");
        }
 
        public void insertTshirt(String annee, String couleur, String taille, int coche) {
                String strSql = "insert into Tshirt (Annee, Couleur, Taille, Coche) values ('" + annee + "','" + couleur + "','" + taille + "'," + coche + ")";
                this.getWritableDatabase().execSQL(strSql);
                Log.i("DATABASE", "Tshirt insert invoked");
        }
 
        public void insertAffiliation(int id_produit, int id_client, String type) {
                String strSql = "insert into Affiliation (Id_produit, Id_client, Type) values (" + id_produit + "," + id_client + ",'" + type + "')";
                this.getWritableDatabase().execSQL(strSql);
                Log.i("DATABASE", "Affiliation insert invoked");
        }
 
        public void insertClient(String prenom, String nom, String mail, String password, String morpho) {
                String strSql = "insert into Client (Prenom, Nom, Mail, Password, Morpho) values (UPPER('" + prenom + "'),UPPER('" + nom + "'),'" + mail + "','" + password + "','" + morpho + "')";
                this.getWritableDatabase().execSQL(strSql);
                Log.i("DATABASE", "Client insert invoked");
        }
 
        public List<Client_WL_Jupe> ReadWLJupe(int id_recherche) {
                List<Client_WL_Jupe> WLJupe = new ArrayList<>();
                String StrSqljupe = "SELECT Jupe.Type_,Jupe.Ref_,Jupe.Couleur,Jupe.Taille FROM Jupe WHERE Jupe.Id IN ( SELECT Id_produit FROM Affiliation WHERE              Id_client="+id_recherche+" AND Type='Jupe')";
                Cursor cursorjupe = this.getReadableDatabase().rawQuery(StrSqljupe, null);
                cursorjupe.moveToFirst();
                while (!cursorjupe.isAfterLast()) {
                            Client_WL_Jupe client_wl_jupe = new Client_WL_Jupe(cursorjupe.getString(0), cursorjupe.getString(1), cursorjupe.getString(2), cursorjupe.getString(3));
                            WLJupe.add(client_wl_jupe);
                            cursorjupe.moveToNext();
                }
                cursorjupe.close();
                return (WLJupe);
        }
 
        public List<Client_WL_Accessoire> ReadWLAccessoire(int id_recherche) {
                List<Client_WL_Accessoire> WLacc = new ArrayList<>();
                String StrSqlacc = "SELECT Accessoire.Type_, Accessoire.Couleur, Accessoire.Motif FROM Accessoire WHERE Accessoire.Id IN ( SELECT Id_produit FROM Affiliation WHERE Id_client="+id_recherche+" AND Type='Accessoire')";
                Cursor cursoracc = this.getReadableDatabase().rawQuery(StrSqlacc, null);
                cursoracc.moveToFirst();
                while (!cursoracc.isAfterLast()) {
                        Client_WL_Accessoire client_wl_accessoire = new Client_WL_Accessoire(cursoracc.getString(0), cursoracc.getString(1), cursoracc.getString(2));
                        WLacc.add(client_wl_accessoire);
                        cursoracc.moveToNext();
                }
                cursoracc.close();
                return (WLacc);
        }
 
        public List<Client_WL_Tshirt> ReadWLTshirt(int id_recherche) {
                List<Client_WL_Tshirt> WLt = new ArrayList<>();
                String StrSqlt = "SELECT Tshirt.Annee, Tshirt.Couleur, Tshirt.Taille FROM Tshirt WHERE Tshirt.Id IN ( SELECT Id_produit FROM Affiliation WHERE Id_client="+id_recherche+" AND Type='Tshirt')";
                Cursor cursort = this.getReadableDatabase().rawQuery(StrSqlt, null);
                cursort.moveToFirst();
                while (!cursort.isAfterLast()) {
                       Client_WL_Tshirt client_wl_tshirt = new Client_WL_Tshirt(cursort.getString(0), cursort.getString(1), cursort.getString(2));
                       WLt.add(client_wl_tshirt);
                       cursort.moveToNext();
                }
                cursort.close();
                return (WLt);
        }
}
D'avance merci