bonjour,
J'ai réussi à afficher un tableau de 750 lignes (checkable) dans un listView.
Ce listView est dans un fragment qui est affiché par l'icon d'un menu.
pour le moment le tableau s'affiche quand on click sur le bouton.
J'aimerai par la suite afficher mon tableau quand je suis sur le fragment qui le contient.
Bref...
Je démarre l'appli, je vais dans le menu, je click sur l'item voulu, je click sur le bouton, le tableau s'affiche.
Je choisi un autre item dans le menu, je reviens sur mon item où j'ai mon bouton, je click dessus il n'affiche plus rien.....
POURQUOI ????
VRAIMENT BESOIN D'AIDE MERCI

PS dans le forum kotlin personne ne répond.
PS 2:ce code est imbriqué dans un le code généré par android studio avec navigation drawer activity
c'est a dire que j'ai laissé les class ViewModel etc... si ça peut aider a comprendre d'où vient le problème (pour moi il vient en effet de la...)

voici le code:
Code Kotlin : 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
fun initListViewData() {
 
        val alim1 = List_aliment("Apéricube (à l’unité)", "16", false)
        val alim2 = List_aliment("Bretzel (à l’unité 15 g)", "80", false)
        //750 lignes
 
val alims: Array<List_aliment> =arrayOf<List_aliment>(
            alim1, alim2, alim3,alim4,alim5, alim6, alim7,alim8,alim9, alim10, alim11,alim12,alim13, alim14, alim15,alim16,alim17, alim18, alim19,alim20)
 
 val arrayAdapter: ArrayAdapter<List_aliment> =
            ArrayAdapter<List_aliment>(this, android.R.layout.simple_list_item_checked, alims)
        this.listView.adapter = arrayAdapter
        for (i in alims.indices) {
            this.listView.setItemChecked(i, alims[i].isActive())
        }
    }
 
  fun btimcclick(view: View) {
        val listView = findViewById<View>(R.id.listView) as ListView
        listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE
 
        initListViewData()
 
    }
oui c'est du kotlin mais vous qui etes pro du java vous n'aurez aucun mal a le lire...

voici le xml...
Code XML : 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
<?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"
    tools:context=".ui.alim.AlimFragment"
    android:orientation="vertical">
 
 
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <Button
                android:id="@+id/btmange"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Lance"
                android:onClick="btimcclick"/>
 
             <ListView
                    android:id="@+id/listView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
              </ListView>
        </LinearLayout>
</LinearLayout>