我对标签有疑问.例如,如果我有一个带有标签ButtonTag"的按钮.标签是一个对象,但我想捕获一个字符串ButtonTag"并在开关内使用.总结一下,得到一个对象标签字符串并在开关中使用.有可能吗?
I have a doubt related with tag. For example, if i have a button with a tag "ButtonTag". Tag is a object, but i would like to catch a string "ButtonTag" and use inside a switch. Summing up, to get a String of Object tag and to use in a Switch. Is possible ?
public void ArtGeneralButton(View view){
selsub = view.getId();
tagsub = view.getTag(); \ Object -> String How???
// String myString = getString(null,tagsub,);
UpdateAnsList myUpdate = new UpdateAnsList(this);
myUpdate.StartUpdateAnsList(selsub,tagsub);
}
String tagString = (String) view.getTag();
只要最初用于设置标签的内容是 String
It's as simple as that as long as whatever was originally used to set the tag was a String
至于在 switch
中使用 String
而言,我更喜欢使用 int
作为 switch<的键/代码>.在这种情况下,我会将标签设置为
ints
- 可以是任意值,例如 1、2、3 等,也可以使用 strings.xml
文件中字符串的资源 ID.
As for using a String
in a switch
is concerned, I prefer to use int
as the key for a switch
. In this case I'd set the tags as ints
- either arbitrary values such as 1, 2, 3 etc or use the resource ids of strings in the strings.xml
file.
这篇关于获取对象标签的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!