Bonjour,

Je suis face à un bug (?) et je me demande si certains d'entre vous l'ont déjà rencontré.

Je construit une ExpandableListView (ELV) et chaque élément Child de cet ELV est en fait une ListView (LV).

Malheureusement dans ma LV, seul 1 élément s'affiche et les autres sont "perdus". Pourtant au débogage je remarque que mon adapter contient la bonne LV avec les bons éléments mais c'est à l'affichage que cela pose problème.

J'ai beau retourner le problème dans tous les sens et je ne trouve pas l'origine de ce soucis. Serait-ce un bug "connu" ?

Bien à vous.

Lionel


Voici le code de mon élément Child qui contient la LV :

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
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    >
 
    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@color/light_blue" >
 
        <TextView
            android:id="@+id/tvRowASC_name"
            android:layout_width="@dimen/colWidth_medium"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:drawableLeft="@drawable/arrow_down"
            android:text="@string/col_asc_name"
            android:textAppearance="@style/AssetSubCatCell" />
 
        <TextView
            android:id="@+id/tvRowASC_valuation"
            android:layout_width="@dimen/colWidth_medium"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/tvRowASC_pc_port"
            android:drawableLeft="@drawable/dollar"
            android:text="@string/col_asc_valuation"
            android:textAppearance="@style/AssetSubCatCell" />
 
        <TextView
            android:id="@+id/tvRowASC_pc_port"
            android:layout_width="@dimen/colWidth_medium"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/tvRowASC_pc_sect"
            android:drawableLeft="@drawable/pie_chart"
            android:text="@string/col_asc_pc_port"
            android:textAppearance="@style/AssetSubCatCell" />
 
        <TextView
            android:id="@+id/tvRowASC_pc_sect"
            android:layout_width="@dimen/colWidth_medium"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:drawableLeft="@drawable/pie_chart"
            android:text="@string/col_asc_pc_sect"
            android:textAppearance="@style/AssetSubCatCell" />
    </RelativeLayout>
 
    <ListView
        android:id="@+id/listViewPosition" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"/>
 
</LinearLayout>
Et le code XML d'une ligne de ma LV

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
<?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="match_parent"
    android:orientation="horizontal"
    android:background="@color/white"
    android:padding="@dimen/padding_medium"
    >
 
    <TextView
        android:id="@+id/tvRowPos_name"
        android:layout_width="@dimen/colWidth_medium"
        android:layout_height="wrap_content"
        android:textAppearance="@style/PositionCell"
        android:text="@string/col_pos_name"
        />
 
    <TextView
        android:id="@+id/tvRowPos_valuation"
        android:layout_width="@dimen/colWidth_medium"
        android:layout_height="wrap_content"
        android:textAppearance="@style/PositionCell"
        android:layout_toLeftOf="@+id/tvRowPos_pc_port"
        android:text="@string/col_pos_valuation"
        />
 
    <TextView
        android:id="@+id/tvRowPos_pc_port"
        android:layout_width="@dimen/colWidth_medium"
        android:layout_height="wrap_content"
        android:textAppearance="@style/PositionCell"
        android:layout_toLeftOf="@+id/tvRowPos_pc_sect"
        android:text="@string/col_pos_pc_port"
        />
 
    <TextView
        android:id="@+id/tvRowPos_pc_sect"
        android:layout_width="@dimen/colWidth_medium"
        android:layout_height="wrap_content"
        android:textAppearance="@style/PositionCell"
        android:layout_alignParentRight="true"
        android:text="@string/col_pos_pc_sect"
        />
</RelativeLayout>
Et la façon dont je crée ma LV (au sein de l'Adapter pour mon ELV)

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
	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = infalInflater.inflate(R.layout.row_asset_sub_cat, null);
		}
		AssetSubCat asc = (AssetSubCat) getChild(groupPosition, childPosition);
 
		//Affichage de la SubCat
		TextView tvAscName = (TextView) convertView.findViewById(R.id.tvRowASC_name);
		tvAscName.setText(asc.getName());
		TextView tvAscValuation = (TextView) convertView.findViewById(R.id.tvRowASC_valuation);
		tvAscValuation.setText(String.valueOf(asc.getValuation()));
		TextView tvAscPcPort = (TextView) convertView.findViewById(R.id.tvRowASC_pc_port);
		tvAscPcPort.setText(String.valueOf(asc.getPc_port()) + "%");
		TextView tvAscPcSect = (TextView) convertView.findViewById(R.id.tvRowASC_pc_sect);
		tvAscPcSect.setText(String.valueOf(asc.getPc_sect()) + "%");
 
 
		//Création de la liste des positions
		listViewPositions = (ListView) convertView.findViewById(R.id.listViewPosition);
		ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
		List<Position> positions =  asc.getPosition();
        for(Position pos : positions){
            //On déclare la HashMap qui contiendra les informations pour un item
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("id",String.valueOf(pos.getId()));
			map.put("name", pos.getName());
			map.put("valuation", pos.getValuation());
			map.put("pc_port", pos.getPc_port());
			map.put("pc_sect", pos.getPc_sect());
        	listItem.add(map);
        }
 
        SimpleAdapter mSchedule = new SimpleAdapter (context, listItem, R.layout.row_position,
                new String[] {"name","valuation","pc_port","pc_sect"},
                new int[] {R.id.tvRowPos_name,R.id.tvRowPos_valuation,R.id.tvRowPos_pc_port,R.id.tvRowPos_pc_sect});
 
         //On attribut à notre listView l'adapter que l'on vient de créer
         listViewPositions.setAdapter(mSchedule);
 
         listViewPositions.setOnItemClickListener(new OnItemClickListener() {			
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Log.d("tag","clic");
 
			}
		});
         convertView.setVisibility( View.VISIBLE);
 
 
		return convertView;
	}