Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème d'affichage Expandable list

Affichage aléatoire des données

    23 décembre 2022 à 1:32:08

    Bonjour, 

    J'ai un soucis avec un expandable list sur 3 niveaux que j'ai réalisé en java pour une application android

    Elle permet d'afficher une liste d'outillage classé dans des familles et sous famille.

    Tout fonctionnait correctement jusqu'a que je renseigne un certain nombre de données dans ma base de données.

    Les outils s'affiche pas correctement et je n'ai aucune indication de la part de l'ide (android studio)

    Je recois les donnée d'un json par une url, je renseigne ensuite les données dans les Hashmap pour ensuite les injecté dans mon adaptateur.

    J'utilise bcp de boucle dans des boucle et donc je pense que l'UI à du mal à suivre ??

    Mon but est donc de comprendre mon problème ! 

    Si vous avez d'autre méthode pour classer mes outils avec une imbrication tel que ça, je suis preneur !

    Voici mon code en main activity:

    public class MaterielActivity extends AppCompatActivity {
        // On défini les variable
        Context context;
        ImageButton btndeco, btnmenu;
        FloatingActionButton btnajout, btnpanier;
        SearchView recherche;
        int a = 0, b = 0;
        ProgressBar progressBar;
        Controle controle;
        String[] message, message1;
        ExpandableListView matosListView;
        CircularRevealRelativeLayout circular;
        TabLayout tabLayout;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_materiel);
            context = this;
    
    
            btnpanier = findViewById(R.id.btnpanier);
            btnajout = findViewById(R.id.btnajoutoutils);
            btndeco = findViewById(R.id.btndeconnexion);
            btnmenu = findViewById(R.id.btnmenu);
            recherche = findViewById(R.id.recherche);
            progressBar = findViewById(R.id.progressmat);
            circular = findViewById(R.id.circular);
            this.controle = Controle.getInstance(this);
            matosListView = findViewById(R.id.listmatos);
            tabLayout = findViewById(R.id.tabLayout);
            //progressBar.setVisibility(View.VISIBLE);
            circular.setVisibility(View.VISIBLE);
            ArrayList<String> famille1 = new ArrayList<>();
            ArrayList<String> typeliste = new ArrayList<>();
            HashMap<String, HashMap<String, HashMap<String, ArrayList<MatosItem>>>> ma = new HashMap<>();
            ArrayList<String> materiauliste = new ArrayList<>();
            HashMap<String, HashMap<String, HashMap<String, ArrayList<MatosItem>>>> materielsItemList = new HashMap<>();
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    FetchData fetchData = new FetchData("http://" + adresseIp.getAdresseIP() + "/jsonmateriels.php");
                    if (fetchData.startFetch()) {
                        if (fetchData.onComplete()) {
                            String json = fetchData.getResult();
                                    try {
                                        HashMap<String, HashMap<String, ArrayList<MatosItem>>> typeItemList = new HashMap<>();
                                        JSONObject jsonObject = new JSONObject(json);
                                        JSONArray jsonArrayOutils = jsonObject.getJSONArray("Outils");
                                        for (int j = 0; j < jsonArrayOutils.length(); j++) {
                                            HashMap<String, HashMap<String, ArrayList<MatosItem>>> typeItemList1 = new HashMap<>();
                                            JSONObject fam = jsonArrayOutils.getJSONObject(j);
                                            String famille = fam.names().getString(0);//permet d'avoir les choses contenu dans la classe soudeurs
                                            JSONArray jsonArrayFamille = fam.getJSONArray(famille);//permet de récupérer le suivant
                                            famille1.add(famille);
                                            for (int i = 0; i < jsonArrayFamille.length(); i++) {
                                                HashMap<String, ArrayList<MatosItem>> matItemList = new HashMap<>();
                                                JSONObject typ = jsonArrayFamille.getJSONObject(i);
                                                String type = typ.names().getString(0);
                                                JSONArray jsonArrayType = typ.getJSONArray(type);
                                                typeliste.add(type);
                                                for (int k = 0; k < jsonArrayType.length(); k++) {
                                                    JSONObject mat = jsonArrayType.getJSONObject(k);
                                                    ArrayList<MatosItem> outils = new ArrayList<>();
                                                    String materiau = mat.names().getString(0);
                                                    JSONArray jsonArraylistout = mat.getJSONArray(materiau);
                                                    materiauliste.add(materiau);
                                                    for (int l = 0; l < jsonArraylistout.length(); l++) {
                                                        JSONObject out = jsonArraylistout.getJSONObject(l);
                                                        String description = out.getString("description");
                                                        String id = out.getString("id");
                                                        String ref = out.getString("ref");
                                                        String code_fourn = out.getString("code_fourn");
                                                        Log.e("boucle",description+id);
                                                        outils.add(new MatosItem(description, id, false, ref, code_fourn));
                                                    }
                                                    matItemList.put(materiau, outils);
                                                }
                                                typeItemList1.put(type, matItemList);
                                            }
                                            materielsItemList.put(famille, typeItemList1);
                                            tabLayout.addTab(tabLayout.newTab().setText(famille));
    
                                        }
                                        ArrayList<String> list = new ArrayList<>();
    
                                         for (String i : Objects.requireNonNull(materielsItemList.get(famille1.get(0))).keySet()) {
                                            list.add(i);
                                             Log.e(TAG, "run: "+i );
                                        }
    
                                        typeItemList = materielsItemList.get(famille1.get(0));
                                        Log.e(TAG, "run: "+typeItemList );
                                        matosListView.setAdapter(new MatosItemAdapter(context, typeItemList,list ));
                                        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                                            @Override
                                            public void onTabSelected(TabLayout.Tab tab) {
                                                // get the current selected tab's position and replace the fragment accordingly
                                                Fragment fragment = null;
                                                if (tab.isSelected()) {
                                                    ArrayList<String> list = new ArrayList<>();
                                                    for (String i : Objects.requireNonNull(materielsItemList.get(famille1.get(tab.getPosition()))).keySet()) {
                                                        list.add(i);
                                                    }
                                                    HashMap<String, HashMap<String, ArrayList<MatosItem>>> typeItemList1 = new HashMap<>();
                                                    typeItemList1 = materielsItemList.get(famille1.get(tab.getPosition()));
                                                    matosListView.setAdapter(new MatosItemAdapter(context, typeItemList1, list));
                                                }
    
                                                FragmentManager fm = getSupportFragmentManager();
                                                FragmentTransaction ft = fm.beginTransaction();
                                                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                                                ft.commit();
                                            }
    
                                            @Override
                                            public void onTabUnselected(TabLayout.Tab tab) {
    
                                            }
    
                                            @Override
                                            public void onTabReselected(TabLayout.Tab tab) {
    
                                            }
                                        });
                                        progressBar.setVisibility(GONE);
    
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                        }
                    }
                }
            });
        
            /**
             * Permet de se déconnecter
             */
            btndeco.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    deco();
                    Intent intent = new Intent(getApplicationContext(), Login.class);
                    startActivity(intent);
                    finish();
                }
            });
    
    
    
    
            /**
             * Permet de revenir au menu
             */
            btnmenu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getApplicationContext(), Menu.class);
                    startActivity(intent);
                    finish();
                }
            });
            /**
             * Permet de voir les commandes qui ont été mises dans le pannier
             */
            btnpanier.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String commande;
                    commande = getIntent().getStringExtra("affaire");
                    if (commande != null) {
                        Intent intent = new Intent(getApplicationContext(), Outillage.class);
                        intent.putExtra("affaire", commande);
                        startActivity(intent);
                        finish();
                    } else {
                        Intent intent = new Intent(getApplicationContext(), CommandeMatos.class);
                        startActivity(intent);
                        finish();
                    }
                }
            });
    
            btnajout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getApplicationContext(), Ajout_Outillage.class);
                    startActivity(intent);
                    finish();
                }
            });
        }
    
        private void deco() {
            this.controle.creerProfil(null, null, null, null, this);
        }
    
    }



    Le JSON que je reçois:

    { "Outils" : [{"Soudeurs" : [{"Fils" : [{"Fil" : [{"description" : "Fil MIG G3SI1 diam 1.2", "id" : "26", "ref" : "bobine de 15 kg", "code_fourn" : "x"},{"description" : "Fourre OK1413 diam 1.2", "id" : "45", "ref" : "bobine 16 kg avec gaz", "code_fourn" : "x"},{"description" : "MIG inox 316L SI diam 1.2", "id" : "46", "ref" : "bobine 15 kg", "code_fourn" : "x"}]}]},{"Materiel de soudure" : [{"Gaine guide" : [{"description" : "fil 25 x 45 4M diam 1.2", "id" : "27", "ref" : "x", "code_fourn" : "x"}]},{"Batterie" : [{"description" : "Warrior AIR ESAB", "id" : "47", "ref" : "x", "code_fourn" : "x"}]},{"Cagoule" : [{"description" : "Couvre nuque noire ESAB", "id" : "48", "ref" : "x", "code_fourn" : "x"}]},{"Protection" : [{"description" : "Ecran de protection bleu", "id" : "49", "ref" : "x", "code_fourn" : "x"},{"description" : "Visiere transparente pour ecran HG930B", "id" : "50", "ref" : "x", "code_fourn" : "x"},{"description" : "Visiere teinte pour ecran HG930B", "id" : "51", "ref" : "x", "code_fourn" : "x"}]},{"Pince" : [{"description" : "Stubby original 400 A", "id" : "52", "ref" : "x", "code_fourn" : "x"},{"description" : "Masse bronze GCB 450 A", "id" : "53", "ref" : "x", "code_fourn" : "x"},{"description" : "Masse bronze GCB 600 A", "id" : "54", "ref" : "x", "code_fourn" : "x"}]}]},{"Electrodes" : [{"OK4627" : [{"description" : "Diam 2.5 x 350 rutile", "id" : "25", "ref" : "x", "code_fourn" : "x"}]},{"OK4800" : [{"description" : "Diam 2.5 x 350", "id" : "32", "ref" : "x", "code_fourn" : "x"},{"description" : "Diam 3.2 x 350", "id" : "33", "ref" : "x", "code_fourn" : "x"},{"description" : "Diam 4 x 350", "id" : "34", "ref" : "x", "code_fourn" : "x"},{"description" : "Diam 5 x 450", "id" : "35", "ref" : "x", "code_fourn" : "x"}]},{"Inox 316 L 17" : [{"description" : "Diam 2.5 x 300", "id" : "36", "ref" : "x", "code_fourn" : "x"},{"description" : "Diam 3.2 x 350", "id" : "37", "ref" : "x", "code_fourn" : "x"},{"description" : "Diam 4 x 350", "id" : "38", "ref" : "x", "code_fourn" : "x"}]},{"Gougeage" : [{"description" : "6 x 305", "id" : "39", "ref" : "x", "code_fourn" : "x"},{"description" : "8 x 305", "id" : "40", "ref" : "x", "code_fourn" : "x"},{"description" : "10 x 305", "id" : "41", "ref" : "x", "code_fourn" : "x"}]},{"Nue" : [{"description" : "9.5 x 914 slice", "id" : "42", "ref" : "x", "code_fourn" : "x"}]}]}]},{"Ajusteurs" : [{"Accessoires" : [{"Nettoyant" : [{"description" : "26.5 kg alfa marine", "id" : "44", "ref" : "x", "code_fourn" : "x"}]}]},{"Hydraulique" : [{"Huile" : [{"description" : "Enerpac HF95Y bidon 5L", "id" : "43", "ref" : "x", "code_fourn" : "x"}]}]}]},{"Machinistes" : [{"Accessoires" : [{"Lame ebavureur" : [{"description" : "E100S (longue) boite de 10", "id" : "30", "ref" : "x", "code_fourn" : "x"},{"description" : "B10S (courte) boite de 10", "id" : "31", "ref" : "x", "code_fourn" : "x"}]}]}]}]}



    Je vous mets des captures d'écran des problèmes :

    • Partager sur Facebook
    • Partager sur Twitter

    Problème d'affichage Expandable list

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown