I want to load data into expandable list view, mProductList contains all the data should load to header and child list. I have loaded the data to header list. But I don't know how to load the data to child list. I have used this tutorial to do my expandable list view (http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/).
Can anyone guide me how can I achieve it please. Any help will be appreciated.
UPDATED
ProductAdapter.java
public class ProductAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private LayoutInflater mInflater;
private boolean mShowQuantity;
private HashMap<String, List<String>> _listDataChild;
public ProductAdapter(Context context, List<String> listDataHeader,
LayoutInflater inflater,
HashMap<String, List<String>> listChildData, boolean showQuantity) {
this._context = context;
this._listDataHeader = listDataHeader;
mInflater = inflater;
mShowQuantity = showQuantity;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@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) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.cart_list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.cart_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;
}
}
Shoppingcart.java
mCartList = ShoppingCartHelper.getCartList();
HashMap<String, List<String>> listDataChild = new HashMap<String, List<String>>();
List<String> listDataHeader = new ArrayList<String>();
List<String> listdescription = new ArrayList<String>();
List<String> listcrust = new ArrayList<String>();
List<String> listsize = new ArrayList<String>();
List<String> listDescriptionOne = new ArrayList<String>();
List<String> listDescriptionTwo = new ArrayList<String>();
List<String> listDescriptionHalf = new ArrayList<String>();
List<String> listExtracheese = new ArrayList<String>();
String description;
String crust;
// Make sure to clear the selections
for (int i = 0; i < mCartList.size(); i++) {
mCartList.get(i).selected = false;
hot_number = mCartList.size();
if (mCartList.get(i).description != null
&& !mCartList.get(i).description.isEmpty()) {
description = mCartList.get(i).description;
listdescription.add(description);
System.out.println("listdescription = " + listdescription);
}
if (mCartList.get(i).crust != null
&& !mCartList.get(i).crust.isEmpty()) {
crust = mCartList.get(i).crust;
listcrust.add(crust);
System.out.println("listcrust = " + listcrust);
}
}
listDataChild.put("listcrust", listcrust);
listDataHeader.addAll(listdescription);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
mProductAdapter = new ProductAdapter(this, listDataHeader,
getLayoutInflater(), listDataChild, true);
// setting list adapter
expListView.setAdapter(mProductAdapter);
}
Screenshot