I am trying to write a custom view for checkboxPreferences. I have:
<CheckBoxPreference
android:key="@string/pref_acceptableads"
android:summaryOff="@string/pref_acceptableads_summary_off"
android:summaryOn="@string/pref_acceptableads_summary_on"
android:title="@string/pref_acceptableads_title"
android:widgetLayout="@layout/helpfulcheckbox_layout" />
and:
<?xml version="1.0" encoding="UTF-8"?>
<ViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/image" />
<CheckBox
android:id="@+id/checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</ViewGroup>
Problem is with my viewgroup. I receive an exception:
03-11 13:49:11.520: E/AndroidRuntime(12286): FATAL EXCEPTION: main 03-11 13:49:11.520: E/AndroidRuntime(12286): Process: org.adblockplus.android, PID: 12286 03-11 13:49:11.520: E/AndroidRuntime(12286): android.view.InflateException: Binary XML file line #2: Error inflating class android.view.ViewGroup 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.createView(LayoutInflater.java:620) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.preference.Preference.onCreateView(Preference.java:489) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.preference.Preference.getView(Preference.java:460) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.AbsListView.obtainView(AbsListView.java:2255) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.makeAndAddView(ListView.java:1790) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.fillDown(ListView.java:691) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.fillFromTop(ListView.java:752) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.ListView.layoutChildren(ListView.java:1616) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.AbsListView.onLayout(AbsListView.java:2087) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.View.layout(View.java:14841) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewGroup.layout(ViewGroup.java:4631) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer.doFrame(Choreographer.java:544) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.os.Handler.handleCallback(Handler.java:733) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.os.Handler.dispatchMessage(Handler.java:95) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.os.Looper.loop(Looper.java:136) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.app.ActivityThread.main(ActivityThread.java:5139) 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Method.invokeNative(Native Method) 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Method.invoke(Method.java:515) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796) 03-11 13:49:11.520: E/AndroidRuntime(12286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612) 03-11 13:49:11.520: E/AndroidRuntime(12286): at dalvik.system.NativeStart.main(Native Method) 03-11 13:49:11.520: E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException: can't instantiate class android.view.ViewGroup 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Constructor.constructNative(Native Method) 03-11 13:49:11.520: E/AndroidRuntime(12286): at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 03-11 13:49:11.520: E/AndroidRuntime(12286): at android.view.LayoutInflater.createView(LayoutInflater.java:594) 03-11 13:49:11.520: E/AndroidRuntime(12286): ... 51 more
Can you give me a hit what is going on?
ViewGroup is an abstract class.
Use another layout as RelativeLayout or LinearLayout
In LogCat you have:
E/AndroidRuntime(12286): Caused by: java.lang.InstantiationException: can't instantiate class android.view.ViewGroup
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With