Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Button inside "include" layout

Refer to the doc: http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html

I have a button inside the included layout, how can I access the button? I don't know the id! How can I define the OnClickListener...?

Please help...

like image 216
chow Avatar asked Jan 24 '11 20:01

chow


People also ask

How to include layout in another layout Android?

To efficiently re-use complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.


1 Answers

The id you have with the include tag is assigned to the root View of the included layout. First get a reference to that View using findViewByid. Then you can call findViewById on that specific View to get a reference to a View inside the layout. So:

View myLayout = findViewById( R.id.cell1 ); // root View id from that link View myView = myLayout.findViewById( R.id.someinnerview ); // id of a view contained in the included file 
like image 86
Jems Avatar answered Sep 23 '22 05:09

Jems