如何访问内部的按钮“包含”布局 [英] How to access Button inside "include" layout
本文介绍了如何访问内部的按钮“包含”布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参阅文档: http ://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
我有一个包含布局内的按钮,我该如何访问按钮?我不知道id!如何定义OnClickListener ...?
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...?
请帮助...
推荐答案
包含标记的id分配给包含布局的根视图。
首先使用findViewByid获取对该视图的引用。然后,您可以在该特定View上调用findViewById以获取对布局内View的引用。所以:
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
这篇关于如何访问内部的按钮“包含”布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文