![](/img/trans.png)
[英]How to open a fragment from a button click which is included in another layout
[英]How to access the button code from an included layout?
我已经将页脚布局包含在我的家庭布局中。 页脚布局包含3个按钮,并且在其对应的页脚类中调用了三个方法。
我可以使用以下include
代码在首页布局上成功显示页脚布局。
<include layout="@layout/footer"/>
我面临的问题是,按钮点击无法执行。 它说没有这样的方法发现异常。
如何访问页脚按钮?
您可以通过以下方式访问该按钮:
Button b = (Button) footerLayout.getChildAt(index);
然后您可以在按钮上附加您喜欢的处理程序。
您也可以使用Button b = (Button) findViewById(idOfButton)
访问它
android将包含的布局视为在代码内部编写,如果您的按钮具有ID,则可以轻松访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.