public class ExpandableListAdapters extends BaseExpandableListAdapter {
private Context _context;
List<String> group_data;
List<String> child_data;
public ExpandableListAdapters(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
Log.e("HEADER SIZE", "" + listDataHeader.size() + "..." + listChildData.size());
}
public ExpandableListAdapters(ServicesFragment servicesFragment, List<String> service_names,List<String> service_desc) {
this._context = servicesFragment.getActivity();
this.group_data = service_names;
this.child_data=service_desc;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return child_data.get(groupPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Log.e("SERVICE LIST","...."+child_data.get(groupPosition));
String description = child_data.get(groupPosition);
//final Double price = data.get(groupPosition).getProducts().get(childPosition).getPrice();
Log.e("ADAPTER", "........" + description);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
if(!description.equals(null)){
txtListChild.setText(description);/*+ " : Rs." + price);*/
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return child_data.size();
}
@Override
public Object getGroup(int groupPosition) {
return group_data.get(groupPosition);
}
@Override
public int getGroupCount() {
return group_data.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = group_data.get(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Ce qui précède est mon code. L'élément enfant est créé deux fois sous chaque élément de groupe. Dans ma liste de groupes et d'enfants, il y a deux éléments. En fait, le résultat attendu pour mon code ci-dessus est:Article enfant créé deux fois dans ExpandableListView Android
Groupe1 child1 Group2 CHILD2
Je ne peux pas trouver l'erreur. S'il vous plaît aidez-moi quelqu'un.
indique l'erreur « get (int) dans la liste ne peut pas être appliquée à (java.lang.String) » –
sur lequel vous en ligne obtenez cette erreur –
se réfèrent cet exemple - http: //www.androidhive.info/2013/07/android-expandable-list-view-tutorial/ –