Hi, recently i was learning on how to make custom ...
# getting-started
k
Hi, recently i was learning on how to make custom views and i'm found out of the resources which using the method to inflate other views(from other xml activity). after trying it out to referencing the custom views in
activity_main.xml
in form of
<com.test_project.library.buttons.TestButton/>
, it did works perfectly, but i found out that i cannot override the text value because the
android:text
doesn't appear from suggestion. is this because the effect from inflating the views? or there is something that missing from the custom views class that i didn't declare it first so i cannot put text value in
activity_main.xml
?
the code of the custom views class
Copy code
class TestButton : RelativeLayout {

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attr: AttributeSet? = null) : super(context, attr) {
        initView()
    }

    constructor(
        context: Context,
        attrs: AttributeSet?,
        defStyleAttr: Int
    ) : super(context, attrs, defStyleAttr) {
        initView()
    }

    private fun initView() {
        val rootView = (context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
            .inflate(R.layout.activity_button_default, this, true)
    }
}
r
Perhaps try #android? It looks like it might be quite an Android specific question.
👍 1
k
okay! thank you for the advice, i'll forward the question to that channel.