i\'m newbie i have problem creating game
execute process
activity_main.xml -> MainActivity.java -> GameLoop.java -> action.xml (error) -> CustomView.java
In case someone works with Kotlin he/she can do that:
class KotlinView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr)
You can find this solution and more details here: https://antonioleiva.com/custom-views-android-kotlin/
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
}
You need to override the other 2 constructors of View in CustomView:
public CustomView(Context context) {
super(context);
init(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
//do stuff that was in your original constructor...
}
You need to implement these constructors also:
//Constructor that is called when inflating a view from XML.
View(Context context, AttributeSet attrs)
//Perform inflation from XML and apply a class-specific base style.
View(Context context, AttributeSet attrs, int defStyle)