android – 可扩展的listview没有孩子

我是 Android开发的新手,也是第一次使用可扩展列表视图.我正在创建一个应用程序,其中我从webservice获取d可扩展列表视图的所有内容.我也从wevservice获取所有内容,但是当可扩展列表视图中没有父级的父项时,可扩展列表视图getchildcount()的自定义适配器方法返回null并给出空指针异常如何只显示列表中的父项两个都没有孩子和两个可用?

谢谢

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

解决方法

只需初始化一个空的子数组,如下所示:
private HashMap<String,ArrayList<String>> mGroupsItems =
        new HashMap<String,ArrayList<String>>();
. . .
mGroupsItems.put(name_of_empty_group,new ArrayList<String>());

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...