ExpandableListView中的空指针异常

时间:2014-01-06 10:48:20

标签: android expandablelistview expandablelistadapter

当我尝试制作ExpandableListView

时,我有附加的异常

任何人都可以帮忙!

enter image description here

这是我的方法

@Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        View childView;

        if (convertView == null) {

            LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            childView = infalInflater.inflate(R.layout.side_menu_child_view,null);
        } else {
            childView = convertView;
        }

        TextView linkName       = (TextView) childView.findViewById(R.id.child_title_text);
        LinkEntity linkEntity   = getChild(groupPosition, childPosition);
        linkName.setText(linkEntity.getDisplayName(true));
        return childView;
    }

这是我列表中的xml

<EditText
    android:id="@+id/search_edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:visibility="gone" />

<ExpandableListView
    android:id="@+id/expandable_side_list_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:cacheColorHint="@android:color/transparent"
    android:childDivider="@null"
    android:childIndicator="@null"
    android:divider="@drawable/side_menu_separator"
    android:dividerHeight="0dp"
    android:groupIndicator="@null"
    android:listSelector="@android:color/transparent" >
</ExpandableListView>

3 个答案:

答案 0 :(得分:2)

我已经通过将divider设置为我的子divider而不是null来解决了这个问题,我不知道为什么,但是不管怎样,谢谢

答案 1 :(得分:0)

尝试删除此行:

LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

并将此行放在if声明之上:

mInflater = LayoutInflater.from(context);

其中mInflater被声明为类变量,如LayoutInflater mInflater;

看看是否有效。

答案 2 :(得分:0)

只需将此添加到您的ExapndableListview即可 机器人:分隔= “@空”