获取对象标签的字符串

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.

这篇关于获取对象标签的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)