【问题标题】:Extended ExpandableListView infalting error [duplicate]扩展的 ExpandableListView 错误 [重复]
【发布时间】:2017-02-14 19:28:11
【问题描述】:

我尝试扩展 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);

【问题讨论】:

  • 检查你的包名。 ExtendedExpandableListView 在 com.myapp 中?
  • package="com.myapp"。是的,是的。
  • 清理构建
  • 为什么叫 super(context, null);只需调用 super(context) 即可。
  • 是的,你必须添加那个构造函数

标签: android xml listview layout android-inflate


【解决方案1】:

问题在于 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>

您在结束标记之前包含了&gt;,使用上面的一个,最后删除&gt;标记

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 2020-06-01
    • 2018-04-14
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2017-03-21
    相关资源
    最近更新 更多