Bonjour,
J'essaie de créer une Listview dans une ListView dans une application Android.
Je rencontre un problème, ma ListeView ne se redimensionne pas. Je vois uniquement une ligne.
Pour ce faire j'utilise 2 adapters. Voici le code de ma listView principale:
mon listview_produitsofcategorie_liste.xml
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 public class ListProduitsOfCategorieAdapter extends ArrayAdapter<ProduitsOfCategorie> { CheckBox mCheckBox; View mRowView; GetListeProduitActivity mGetListeProduitActivity; @SuppressLint("ViewHolder") @Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View rowView = inflater.inflate(R.layout.listview_produitsofcategorie_liste, parent, false); TextView titreView = (TextView) rowView.findViewById(R.id.textViewProduitListe); titreView.setTypeface(null, Typeface.BOLD); if(getItem(position)!=null) if(getItem(position).getCategorie().getTitre()!=null) titreView.setText(getItem(position).getCategorie().getTitre()); ListView mListeViewProduit = (ListView) rowView.findViewById(R.id.listviewproduit); if(mGetListeProduitActivity!=null) { ListProduitListeAdapter mListProduitAdapter=new ListProduitListeAdapter(mGetListeProduitActivity,getItem(position).getProduits()); mListeViewProduit.setAdapter(mListProduitAdapter); } /*else { mListProduitsOfCategorieAdapter.notifyDataSetChanged(); }*/ return rowView; } public ListProduitsOfCategorieAdapter(Context context, List<ProduitsOfCategorie> list) { super(context, R.layout.listview_produit_liste, list); } public ListProduitsOfCategorieAdapter(GetListeProduitActivity activity, List<ProduitsOfCategorie> list) { super(activity, R.layout.listview_produit_liste, list); mGetListeProduitActivity=activity; } }
Et ma 2ème ListView
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"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/boder_black" > <TextView android:id="@+id/textViewProduitListe" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="2dp" android:layout_marginStart="2dp" android:gravity="center_vertical" android:textColor="#000000" android:textSize="14sp" /> <View android:id="@+id/dividerhorizontal" android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignLeft="@+id/textViewProduitListe" android:layout_below="@+id/textViewProduitListe" android:background="#aaaaaa" /> <ListView android:id="@+id/listviewproduit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textViewProduitListe" android:layout_below="@+id/dividerhorizontal" android:divider="@android:color/transparent" android:dividerHeight="1dp" /> </RelativeLayout>
listview_produit_liste.xml
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 public class ListProduitListeAdapter extends ArrayAdapter<Produit> { public int RESULT_EDIT_PRODUITMODEL=1; public int RESULT_EDIT_CATEGORIE=2; CheckBox mCheckBox; View mRowView; GetListeProduitActivity mGetListeProduitActivity; @SuppressLint("ViewHolder") @Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View rowView = inflater.inflate(R.layout.listview_produit_liste, parent, false); TextView titreView = (TextView) rowView.findViewById(R.id.textViewProduitListe); if(getItem(position)!=null) if(getItem(position).getTitre()!=null) titreView.setText(getItem(position).getTitre()); ImageView imgView = (ImageView) rowView.findViewById(R.id.imageProduitListe); if(getItem(position).getAvatar()!=null) { String url = getItem(position).getAvatar(); Picasso.with(getContext()) .load(url) .placeholder(R.drawable.ic_loader) .error(R.drawable.ic_defaut_liste) .into(imgView); } TextView qteView = (TextView) rowView.findViewById(R.id.textViewQteProduitListe); if(getItem(position)!=null) if(getItem(position).getQte()!=null) qteView.setText(getItem(position).getQte().toString()); return rowView; } public ListProduitListeAdapter(Context context, List<Produit> list) { super(context, R.layout.listview_produit_liste, list); } public ListProduitListeAdapter(GetListeProduitActivity activity, List<Produit> list) { super(activity, R.layout.listview_produit_liste, list); mGetListeProduitActivity=activity; }
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 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/imageProduitListe" android:layout_marginLeft="1dp" android:layout_marginRight="1dp" android:layout_marginTop="1dp" android:layout_marginBottom="1dp" android:src="@drawable/img_default" android:contentDescription="imageProduit" android:layout_height="60dp" android:layout_width="60dp" android:adjustViewBounds="true" /> <TextView android:id="@+id/textViewProduitListe" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" android:textSize="18sp" android:textColor="#000000" android:layout_marginLeft="5dp" android:layout_marginStart="5dp"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="41dp" android:orientation="horizontal" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_gravity="end" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="@android:color/darker_gray"/> <CheckBox android:id="@+id/CheckBoxProduitListe" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" android:layout_marginRight="5dp" android:layout_marginEnd="5dp" android:layout_marginLeft="5dp" android:layout_marginStart="5dp" android:textSize="18sp" /> </LinearLayout> </RelativeLayout >
J'ai l'impression que la 2ème ListView ne se redimensionne pas. Comment je peux faire pour que la ListView s'élargie pour afficher tous les produits?
Partager