安卓:View.getTag / setTag和抛出:IllegalArgumentException [英] Android: View.getTag/setTag and IllegalArgumentException

查看:152
本文介绍了安卓:View.getTag / setTag和抛出:IllegalArgumentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我知道调用这些功能,需要一个关键的版本,当你需要一个独特的资源ID,但我不能为我的生活弄清楚如何创建一个资源ID,可以以这种方式使用。在我的课不会工作的最后一个变量,所以并不会有硬codeD值。这两种扔一个IllegalArgumentException。那么是什么原因,你如何使用这些方法?

Yes, I know you need a unique resource id when calling the version of these functions that requires a key, but I cannot for the life of me figure out how to create a resource id that can be used in this way. A final variable in my class wont work and neither will a hard coded value. Both threw an IllegalArgumentException. So what gives, how do you use these methods?

Spara

推荐答案

从<一个href="http://developer.android.com/reference/android/view/View.html#setTag%28int,%20java.lang.Object%29">the的Javadoc :

指定的重点应该是一个ID的在应用程序的资源的声明,以确保它是独一无二的。

The specified key should be an id declared in the resources of the application to ensure it is unique.

所以,你不能只是弥补值,并将其放置在一个局部变量。

So you can't just make up values and place them in a local variable.

在创建它是否是一个字符串,每个资源( R.string。* ),或布局( R.layout。* )或单个查看 R.id。* )可以有一个ID。这是你必须做了。

Every resource you create whether it's a string (R.string.*), or a layout (R.layout.*) or an individual View (R.id.*) can have an ID. This is something you must be doing already.

如果您需要存储多个对象针对单个查看,那么你就需要使用 R.id 变体作为重点,如 someView.setKey(R.id.my_key_1,someObject)

If you do need to store multiple objects against a single View, then you need to use the R.id variant as a key, like someView.setKey(R.id.my_key_1, someObject).

这篇关于安卓:View.getTag / setTag和抛出:IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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