什么是浏览方法getID()返回? [英] What does View method getId() return?

查看:162
本文介绍了什么是浏览方法getID()返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是视图的的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 the android:id value, or the value you set via setId().

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 as R.id.field1 and R.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 a HashMap to map between the getId() values and your "very important" numbers. Or, find some other solution that does not involve magic names on your ID values.

这篇关于什么是浏览方法getID()返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆