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.
这篇关于获取对象标签的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取对象标签的字符串
基础教程推荐
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
