Reputation: 715
I have a class extending RelativeLayout like so:
class CustomLayout extends RelativeLayout {
CustomLayout(Context context) {
super(context, null, 0);
}
CustomLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
CustomLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
I make use of this layout through the XML file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.vj.myapp.CustomLayout
android:id="@+id/imageView_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#555"
android:layout_weight="1">
</com.vj.myapp.CustomLayout>
</LinearLayout>
But the app crashes with:
Error inflating class com.vj.myapp.CustomView
I did provide the required constructors. What's going on?
Upvotes: 1
Views: 763
Reputation: 1489
If you use Android Studio the easiest may is hit ctrl+o and choose methods to override. It will generate stubs with correct signatures, then you can modify code as you wish.
Upvotes: 1