Не удалось получить значение от дочернего элемента в расширяемом представлении списка

Не удалось получить значение от дочернего элемента в расширяемом представлении списка. У меня есть два параметра в списке..

частная карта > ExpCollection; частные ноутбуки Список;

И пытаемся получить значение из ExpCollection в getChildView() и setText() в price TextView.. . его бросающее исключение нулевого указателя..

Пожалуйста помоги...

Код адаптера: -

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;
    }
}

person Vijay Laxmi    schedule 04.10.2013    source источник
comment
Пожалуйста, опубликуйте свой logcat, тогда только один из них сможет предоставить решение вашей проблемы.   -  person GrIsHu    schedule 04.10.2013
comment
Пробовали ли вы отлаживать свой код и проверять, является ли значение laptop нулевым или нет?   -  person GrIsHu    schedule 04.10.2013


Ответы (1)


Используйте следующее:

        if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater)this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.child_item, null);
person Subhalaxmi    schedule 04.10.2013