什么是浏览方法getID()返回? [英] What does View method getId() return?
问题描述
什么是视图的的getId之间的合作关系()方法和XML文件中定义的ID?有没有?我的ID是这样的:字段1,字段2......这数字结尾是我的应用程序非常重要,我需要找回它们。有没有办法做到这一点?
什么是浏览的的getId(之间的)方法和标识的XML文件中定义的合作关系?
块引用>
的getId()
返回的android:ID
值,或通过SETID()
。
我的ID是这样的:字段1,字段2
块引用>在你的XML,它们可能看起来像
@ + ID /字段1
和@ + ID /域2
。这些都是分配ID资源,这是在编译时转换为数字。这些都是你指的是Java的code作为R.id.field1号码
和R.id.field2
。
这数字结尾是我的应用程序非常重要,我需要找回它们。有没有办法做到这一点?
块引用>不得不
R.id.field1
一个大的switch语句比较ID等,或设立了的HashMap
到的getId()
的价值观和非常重要的数字之间进行映射。或者,发现并没有对你的ID值涉及到魔法姓名一些其他的解决方案。What is the co-relation between View's getId() method and the id defined in the XML file? Is there any? My IDs look like this: "field1", "field2"... This digits at the end are very important for my application and I need to retrieve them. Is there any way to do it?
解决方案What is the co-relation between View's getId() method and the id defined in the XML file?
getId()
returns theandroid:id
value, or the value you set viasetId()
.My IDs look like this: "field1", "field2"
In your XML, they may look like
@+id/field1
and@+id/field2
. Those are allocating ID resources, which are turned into numbers at compile time. These are the numbers you refer to in Java code asR.id.field1
andR.id.field2
.This digits at the end are very important for my application and I need to retrieve them. Is there any way to do it?
Have a big switch statement comparing the ID to
R.id.field1
, etc. Or, set up aHashMap
to map between thegetId()
values and your "very important" numbers. Or, find some other solution that does not involve magic names on your ID values.这篇关于什么是浏览方法getID()返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!