扩展的ExpandableListView infalting错误

时间:2016-10-06 06:54:24

标签: android xml listview layout android-inflate

我试图扩展ExpandableListView类,但得到:

android.view.InflateException
Binary XML file line #30: Binary XML file line #30: Error inflating class com.myapp.ExtendedExpandableListView

我的自定义ExpandableListView:

public class ExtendedExpandableListView extends ExpandableListView {

    public ExtendedExpandableListView(Context context) {
        super(context, null);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        try {
            super.dispatchDraw(canvas);
        } catch (IndexOutOfBoundsException e) {
            Log.e("LOG", "Ignore list view error ->" + e.toString());
        }
    }
}

布局的xml中定义的元素:

<com.myapp.ExtendedExpandableListView
        android:id="@+id/customListViewElement"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:animateLayoutChanges="true"
        android:dividerHeight="0dp"
        android:divider="@android:color/transparent"
        android:groupIndicator="@null"
        android:listSelector="@android:color/transparent"
        android:showDividers="middle" >
</com.myapp.ExtendedExpandableListView>

在片段中膨胀:

myListView = (ExtendedExpandableListView) mView.findViewById(R.id.customListViewElement);

1 个答案:

答案 0 :(得分:0)

问题在于XML

list

您在结束标记之前已包含<com.myapp.ExtendedExpandableListView android:id="@+id/customListViewElement" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none" android:animateLayoutChanges="true" android:dividerHeight="0dp" android:divider="@android:color/transparent" android:groupIndicator="@null" android:listSelector="@android:color/transparent" android:showDividers="middle" </com.myapp.ExtendedExpandableListView> 使用上面的标记,并在末尾删除>标记