I have a custom button that I build using anko DSL:
fun customButton(label: String): View {
return UI {
verticalLayout {
button {
id = BTN_SERVICE_ITEM_ID
}.lparams(dip(64), dip(64))
textView {
text = label
}.lparams(wrapContent, wrapContent)
}
}.view
}
then I add setOnClickListener
on that button
val customButton = customButton("service 1")
layout.addView(customButton)
customButton.setOnClickListener {
toast("clicked")
}
when I click the button, the toast is not shown. But when the area of the custom button is clicked, the toast is shown.
I know I can use findViewById
to get the button then add setOnClickListener
to it. But, is there any method so I can just attach onClickListener to the view?
EDIT:
I already try to add isEnabled=false
, isClickable=false
, isFocusable=false
, isActivated=false
and setOnClickListener(null) on the button. Still no luck.