【发布时间】: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