ExpandableListView ne se déroule pas et affiche aucun contenu
bonjour,
je suis sur un projet et j'ai besoin d'un ExpandableListView, j'ai suivit ce tuto https://www.youtube.com/watch?v=iMoN414EfSQ j'ai tout suivit mais ma View ne se déploie pas.
sachant que je n'ai aucun error dans mon logcat le seul message qui s'affiche quand j'appuis sur mon ExpandableListView c'est : D/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0.
Pourtant j'ai bien introduit du contenu dans le child.
Code java de l'activité principale:
Code:
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
| package com.example.bjrcontrole;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class compte_rendu extends AppCompatActivity {
ExpandableListView expandableListView;
List<String> title;
Map<String, List<String>> controle;
ExpandableListAdapter listAdapater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compte_rendu);
expandableListView = (ExpandableListView) findViewById(R.id.ExpandableListView);
fillData();
listAdapater = new myListAdapter(this,title,controle);
expandableListView.setAdapter(listAdapater);
}
public void fillData (){
title = new ArrayList<String>();
controle = new HashMap<String, List<String>>();
title.add("Controle non conforme :");
List<String> nonComforme = new ArrayList<String>();
nonComforme.add("test1");
nonComforme.add("test2");
nonComforme.add("test3");
controle.put(title.get(0),nonComforme);
}
} |
Code java de ma ListAdapter:
Code:
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| package com.example.bjrcontrole;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import java.util.List;
import java.util.Map;
public class myListAdapter extends BaseExpandableListAdapter {
Context context;
List<String> title;
Map<String, List<String>> controle;
public myListAdapter(Context context, List<String> title, Map<String, List<String>> controle) {
this.context = context;
this.title = title;
this.controle = controle;
}
@Override
public int getGroupCount() {
return title.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return controle.get(title.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return title.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return controle.get(title.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String titre = (String) getGroup(groupPosition);
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_group,null);
}
TextView txttittle = (TextView) convertView.findViewById(R.id.title);
txttittle.setText(titre);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String ctrl = (String) getChild(groupPosition, childPosition);
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item,null);
}
TextView txtcontrole = (TextView) convertView.findViewById(R.id.textItem);
txtcontrole.setText(ctrl);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
} |
XML de l'activité principal:
Code:
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
| <?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".compte_rendu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView75"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Controle conforme :" />
<TextView
android:id="@+id/textView81"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="oui"/>
</TableRow>
<ExpandableListView
android:id="@+id/ExpandableListView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ExpandableListView>
</LinearLayout>
</ScrollView> |
XML des titre/group :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="titre" />
</LinearLayout> |
XML de mon contenu :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test1" />
</LinearLayout> |
Voila j'espére que vous aller reussir a m'aider.
Merci d'avance pour vos réponse.