Search code examples
androidandroid-custom-view

Can I make a custom constructor for a custom view?


I have custom view extended from Constraint Layout.I only use it programmatically, without xml inflation.

Am I able to do like this without any hidden problems?

abstract class AbstractView(context: Context, var myParam: Any) : ConstraintLayout(context){

init {
    View.inflate(context, getLayout(), this)
}

Solution

  • As I found you are able to do this without any drawbacks, but you just can't use them inside XML file.