如何访问“包含"内的按钮布局 [英] How to access Button inside "include" layout
本文介绍了如何访问“包含"内的按钮布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
参考文档:http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
我在包含的布局中有一个按钮,如何访问该按钮?我不知道身份证!如何定义 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 获取对该视图的引用.然后您可以在该特定视图上调用 findViewById 以获取对布局内视图的引用.所以:
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屋!
查看全文