无法从可扩展列表视图中的子级获取值。我有两个 列表中的参数..
私人地图> ExpCollection;私人的 列出笔记本电脑;
尝试从价格TextView中的getChildView()和setText()中获取ExpCollection的值。它抛出空指针异常..
请帮助......
适配器代码: -
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Activity context;
private Map<String, List<String>> ExpCollection;
private List<String> laptops;
public ExpandableListAdapter(Activity context, List<String> laptops,
Map<String, List<String>> ExpCollection) {
this.context = context;
this.ExpCollection = ExpCollection;
this.laptops = laptops;
}
public Object getChild(int groupPosition, int childPosition) {
return ExpCollection.get(laptops.get(groupPosition)).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String laptop = (String) getChild(groupPosition, childPosition);
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.child_item, null);
}
TextView item = (TextView) convertView.findViewById(R.id.laptop);
TextView price = (TextView) convertView.findViewById(R.id.runTime1);
TextView discountPrice = (TextView) convertView.findViewById(R.id.runTime);
System.out.println("ExpCollection******** "+ExpCollection.toString());
// price.setText(ExpCollection.get("price").toString());
//discountPrice.setText(ExpCollection.get("discountPrice").toString());
RelativeLayout delete = (RelativeLayout) convertView
.findViewById(R.id.layout);
item.setText(laptop);
return convertView;
}
public int getChildrenCount(int groupPosition) {
return ExpCollection.get(laptops.get(groupPosition)).size();
}
public Object getGroup(int groupPosition) {
return laptops.get(groupPosition);
}
public int getGroupCount() {
return laptops.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String laptopName = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_item, null);
}
TextView item = (TextView) convertView.findViewById(R.id.laptop);
item.setTypeface(null, Typeface.BOLD);
item.setText(laptopName);
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
答案 0 :(得分:0)
使用以下内容:
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater)this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_item, null);