How to create a simple custom View?

I would like to create an custom View on Android. I have tried to do it as simple as possible and created an almost empty class MyView and used it in my LinearLayout but the application fails on start with "Force Close". How can I do a simple custom View? According to Building Custom Components the View gets the size 100x100 if I don't override onMeasure().

public class MyView extends View {

    public MyView(Context context) {
        super(context);
    }
}

And I use it in a LinearLayout with:


What am I doing wrong?


If I use the constructor that itemon suggest and the corresponding call to the superclass. Then the "Force Close" is gone, but my LinearLayout is broken, the components after MyView isn't shown.

Here is my main.xml:







9
задан Community 23 May 2017 в 10:29
поделиться