Button click event not working in a included activity, inside another activity

76 Views Asked by At

I have parent activity with drawerlayout, in it's xml I put dashboard layout using include tag and in xml of this dashboard layout I put 'MainActivity' using include tag again. In the xml of MainActivity there is button, for which in onclick I put some logic in MainActivity.java. Problem is button is rendering, but click is not working anyway

  1. I want to write business logic for click in MainActivity.java, that button which is in xml of MainActivity.xml.
  2. Button click must work in this way
1

There are 1 best solutions below

1
On

Suppose, You have used <include tag in ParentActivty and you have given id as "@+id/layout_button" And also in ChildActivity you have given Button id as "@+id/button"

If you use "viewbinding" in your codebase then you can get the reference of this button by calling binding.layoutButton.button