https://kotlinlang.org logo
#getting-started
Title
# getting-started
w

Will Nixon

08/24/2020, 12:46 PM
Hi all, tried to find an answer on Google/SO but not had much luck - I want to create a class that extends Constraint Layout so that I can add it dynamically to a view based on a toggle switch. I know that extending ConstraintLayout requires 3 constructor methods, but is there a way to pass in additional parameters when initializing the cutsom class? Ie. an array that I can then use in the custom class?
m

Michael

08/24/2020, 1:57 PM
You can use something like this
Copy code
class MyLayout(val customParameter: Type, Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes) : ConstraintLayout(context, attrs, defStyleAttr, defStyleRes)
You don’t need to pass all arguments of your class to the super constructor
w

Will Nixon

08/24/2020, 2:03 PM
ah that’s super helpful, thank you!
m

Michael

08/24/2020, 2:08 PM
you're welcome
3 Views