【发布时间】:2016-10-17 12:06:34
【问题描述】:
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;
}
}
以上是我的代码。 子项在每个组项下创建两次。 在我的组和子列表中有两个元素。实际上我上面的代码的预期结果是:
组 1 子 1 组 2 子 2
我找不到错误。请任何人帮助我。
【问题讨论】:
标签: android expandablelistview repeat expandablelistadapter