2013-04-22 15 views
9

Sono nuovo nello sviluppo di Android e utilizza anche listview espandibile per la prima volta. Sto creando un'app dove ottengo tutti i contenuti di d listview espandibile dal webservice. Ottengo tutti i contenuti dal wevservice, ma poi quando non ci sono figli di un genitore in listview espandibile l'adattatore personalizzato merhod di listview espandibile getchildcount() restituisce null e fornisce un'eccezione di puntatore nullo come posso mostrare solo genitore nell'elenco con nessun bambino ed entrambi quando entrambi sono disponibili ??ListView espandibile senza bambini

Grazie

public View getChildView(int p_id, int c_id, boolean bln1, View view,ViewGroup viewgroup) { 
    // TODO Auto-generated method stub 

    if (view == null) { 
      view = inflater.inflate(com.example.eventlive.R.layout.homescreen_list_item_child, viewgroup,false); 
     } 

     TextView textView = (TextView) view.findViewById(R.id.list_item_text_child); 
     //"i" is the position of the parent/group in the list and 
     //"i1" is the position of the child 
     textView.setText(mParent.get(p_id).getArrayChildren().get(c_id)); 
     view.setBackgroundResource(R.drawable.child_bg); 
     //return the entire view 
     return view; 
} 

//counts the number of children items so the list knows how many times calls getChildView() method 
@Override 
public int getChildrenCount(int p_id) { 
    // TODO Auto-generated method stub 
    return mParent.get(p_id).getArrayChildren().size(); 
} 
+0

pubblicare il tuo codice .. – Pragnani

risposta

16

Basta inizializzare un array bambini vuoto come questo:

private HashMap<String, ArrayList<String>> mGroupsItems = 
     new HashMap<String, ArrayList<String>>(); 
. . . 
mGroupsItems.put(name_of_empty_group, new ArrayList<String>()); 
+0

Puoi informi mera dove dobbiamo inizializzare questo array figli vuoto? Sto affrontando lo stesso numero –

+0

@Alexandar Zhak, per favore rispondi –

+0

@Sharp edge Nel tuo activity onCreate(), dove inizializzi ExpandableListView e configuralo Adapter. –

Problemi correlati