How to access Button inside “include” layout

后端 未结 5 1713
不知归路
不知归路 2020-12-13 12:36

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 a

5条回答
  •  甜味超标
    2020-12-13 13:05

    Actually include tags include all the elements in your root layout. So you can always access them using findViewById on your Activity.

    Suppose you have a alayout.xml in which there is a include layout. Now in one of your activity A,inside onCreate you declared setContentView(R.layout.alayout) Now inside your include layout you might have a button with id myBtn. You can access that inside onCreate in the same way you could access it if it were in main layout: findViewById(R.id.myBtn)

提交回复
热议问题