To get a String of Object tag(获取对象标签的字符串)
问题描述
我对标签有疑问.例如,如果我有一个带有标签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.
这篇关于获取对象标签的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取对象标签的字符串


基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01