Bonjour,
je suis encore débutante en android et j'ai besoin d'aide. Je dois faire une partie d'une application gestion courses. L'idée est de créer une première interface qui liste les différentes catégories : texte + image comme montre l'image ci-dessous:

Nom : cat.png
Affichages : 159
Taille : 277,9 Ko


donc pour mettre les images sous ce format je dois utiliser un GridLayout mais je n'arrive pas à le faire avec mon code. Je le mets mais il affiche uniquement le texte.
Quelqu'un peut m'aider dans ce sens là, comment utiliser un GridLayout dans mon cas et en même temps avec la base SQLite car j'ai créer la Table catégorie ?


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
 
 
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
 
import com.example.a.Entity.CategorieEntity;
 
import java.util.ArrayList;
 
public class MainActivity extends AppCompatActivity {
    ArrayList<CategorieEntity> listCategories;
    LinearLayout layoutBtn;
    ArrayList<LinearLayout> listlayoutBtnText;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listCategories = new ArrayList<CategorieEntity>();
        CategorieEntity fruit = new CategorieEntity(1, "Fruit", "desc cate 1", "https://openclipart.org/image/2400px/svg_to_png/280304/set-icone-frutta.png");
        CategorieEntity legume = new CategorieEntity(2, "Legumes", "desc 2", "https://icon-icons.com/icons2/53/PNG/256/fruits_vegetables_10762.png");
        listCategories.add(fruit);
        listCategories.add(legume);
        layoutBtn = (LinearLayout) findViewById(R.id.layoutImageButton);
        listlayoutBtnText = new ArrayList<LinearLayout>();
        for (int i = 0; i < listCategories.size(); i++) {
            //imageCategories.setScaleType(ImageView.ScaleType.FIT_XY);
            ImageView imageCategories = new ImageView(getApplicationContext());
 
 
            GestionImage.loadImageFromUr(getApplicationContext(), listCategories.get(i).getImageCategorie(), imageCategories);
            TextView libelleCategories = new TextView(getApplicationContext());
            libelleCategories.setText(listCategories.get(i).getLibelleCategorie());
            LinearLayout layoutBtnText = new LinearLayout(getApplicationContext());
            layoutBtnText.addView(imageCategories);
            layoutBtnText.addView(libelleCategories);
            listlayoutBtnText.add(layoutBtnText);
            final int finalI = i;
            imageCategories.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    long idCategorie = listCategories.get(finalI).getIdCategorie();
                    Intent intent = new Intent(getApplicationContext(), ListSelonCategorie.class);
                    intent.putExtra("idCategories", idCategorie);
                    startActivity(intent);
                }
            });
        }
        for (int i = 0; i < listlayoutBtnText.size(); i++) {
            layoutBtn.addView(listlayoutBtnText.get(i));
        }
    }
}
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
 
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.zied.coivoturageetudiant.MainActivity">
 
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:rowCount="2"
            android:columnCount="2">
        <!--LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"!-->
 
            <LinearLayout
                android:id="@+id/layoutImageButton"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"></LinearLayout>
 
         </GridLayout>
    </ScrollView>
 
</LinearLayout>
Remarque : pour layout lorsque j'ai fait avec linear layout ça fonctionne bien alors qu'avec gridlayout ça ne marche pas .
Quelqu'un a une idée comment je puisse faire ?
Merci.