Custom SurfaceView causing NoSuchMethodException

前端 未结 1 1293
小蘑菇
小蘑菇 2020-12-17 04:50

I have a custom View extending SurfaceView. The XML layout is



        
相关标签:
1条回答
  • 2020-12-17 05:14

    You don't have the correct constructor MyCustomView(Context,AttributeSet)

    You must create the following constructors if you want to inflate views, and create new one in code. use initYourStuff() to init your stuff ;) , you can also parametrize them of course...

    public MyCustomView(Context context)
    {
        super(context);
        this.context = context;
        initYourStuff();
    
    }
    
    public MyCustomView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        this.context = context;
        initYourStuff();
    }
    
    public MyCustomView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        this.context = context;
        initYourStuff();
    }
    
    0 讨论(0)
提交回复
热议问题