.java not using the 2- or 3-argument View constructors; XML attributes will not work

后端 未结 4 717
不知归路
不知归路 2020-12-09 04:10

i\'m newbie i have problem creating game

execute process

activity_main.xml -> MainActivity.java -> GameLoop.java -> action.xml (error) -> CustomView.java

4条回答
  •  孤街浪徒
    2020-12-09 04:41

    I think it depends how You creating Your custom view and how You gonna use it .
    Not all 3 constructors really necessary.
    If You create the view with attributes xml file, but won't use defstyle, its enough to call

    public CustomView(Context context, AttributeSet attrs) {
        this(context, attrs);
        //Your code
    }
    

    if You not using attributes and defstlye /i saw examples for this/ You happy to call only

    public CustomView(Context context) {
        super(context);
        //Your code
    }
    

    and if You want use defstyle and attributes too

    public CustomView(Context context, AttributeSet attrs) {
        this(context, attrs);
        //Yourcode
    }
    

提交回复
热议问题