我正在开发一个将显示一些可扩展列表的应用程序。事实是有时对象不会有任何孩子。所以我想在我的可扩展列表中只显示有子元素的元素。我试图在 getGroupView 函数中放置一个 if ,如果该对象没有子对象,我返回 null 但我得到一个 nullPointerException 错误......
这是功能:
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;
}
有没有办法跳过这个功能?
谢谢