获取一串对象标签 [英] To get a String of Object tag

查看:40
本文介绍了获取一串对象标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对标签有疑问.例如,如果我有一个带有ButtonTag"标签的按钮.Tag 是一个对象,但我想捕获一个字符串ButtonTag"并在开关内使用.总结一下,获取一个String of Object标签并在Switch中使用.可能吗?

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.

这篇关于获取一串对象标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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