2013-03-27 98 views
0

我正在研究一个将显示一些可展开列表的应用程序。事实是有时物体不会有任何孩子。所以我想在我的可扩展列表中只显示有孩子的元素。 我试图把一个if getGroupView函数内部,如果对象有没有孩子,我返回null,但我得到一个NullPointerException异常错误...可扩展列表视图android

下面是函数:

public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { 

    // Check if the object as child 
    System.out.println("Result list :: " + mParent.get(i).getListe()); 

      if(mParent.get(i).getListe().isEmpty()){ 
     return null; 
    } 

    if (view == null) { 
     view = inflater.inflate(R.layout.list_item_parent, viewGroup,false); 
    } 



    TextView textView = (TextView) view.findViewById(R.id.list_item_text_view); 
    //"i" is the position of the parent/group in the list 
    textView.setText(getGroup(i).toString()); 

    // Set the Image View with the brand logo 
    ImageView logo = (ImageView) view.findViewById(R.id.brandlogo); 

    // Set image Source 
    logo.setImageResource(mParent.get(i).getLogoPath()); 

    // Set Image size  
    logo.getLayoutParams().height = 42; 
    logo.getLayoutParams().width = 226; 

    //return the entire view 
    return view; 
} 

是否有方式做跳过这个功能?

感谢

回答

1

getGroupCount()函数返回的项目与CHILDES(项目数量有CHILDES)的数量。
并在getGroubView()返回正确的视图(永远不会在这里返回null)。

+0

你是什么意思'返回正确的看法'? – 2013-03-27 20:41:26

+0

有一个孩子在那个位置的视图 – JafarKhQ 2013-03-27 20:42:23

+0

但是如果这个组没有孩子,我会返回什么? – 2013-03-27 20:43:06