2013-10-04 3 views
0

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

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

И пытаясь получить значение из ExpCollection в getChildView() и setText() в цене 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; 
    } 
} 
+0

Пожалуйста, ваши LogCat тогда только один может быть в состоянии обеспечить решение вашей проблемы. – GrIsHu

+0

Вы пробовали отлаживать свой код и проверять, что значение «laptop» равно null или нет? – GrIsHu

ответ

0

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

 if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater)this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.child_item, null); 
Смежные вопросы