简体   繁体   中英

How to access the button code from an included layout?

I had included the footer layout inside my home layout. The footer layout contains 3 buttons and it calls three methods in its corresponding footer class.

I am successfully able to display my footer layout on the home layout using the below include code.

<include layout="@layout/footer"/>

The problem i am facing is , the button clicks are not getting executed. It says no such method found exception.

How does the footer buttons can be accessed ?

you can access the button this way :

Button b = (Button) footerLayout.getChildAt(index);

and then you can attach at the button the handler that you prefer.

You can also access it with Button b = (Button) findViewById(idOfButton)

android treats included layouts as if they were written inside the code, if your button has an id, it is reachable easily

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM