转换含有一个ID为整数ID字符串 [英] Convert String containing an ID into an Integer-ID

查看:193
本文介绍了转换含有一个ID为整数ID字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的问题:

这怎么可能把字符串转换,包含可绘制,这是

How is it possible to convert a String, containing the Id of a Drawable, which is

String idString = "R.drawable.bubblegum";

一个整数,

idInt

这样我就可以使用该ID的图像的参考(,这是用在SimpleAdapter)

so that I can use that ID for the reference of an image (, which is used in a SimpleAdapter)

因此​​,做出了榜样,我不能做到这一点:

So, to make an example, I can't do that:

bubble.setImageDrawable(this.getResources().getDrawable(idString));
//not possible, cause idString is a String an not an Id/Int

所以,我认为是一个包含了ID字符串,但遗憾的是作为一个字符串。

So, I have the String that's containing the id, but unfortunately as a String.

谢谢!

推荐答案

至少,我不能让这个问题的解决方案。看来,有没有办法一个字符串R.id.mytext转换成像R.id.mytext一个整数,可以在findViewById(R.id.myText)被使用。

At least, I couldn't get a solution for this problem. It seems that there's no way to convert a String "R.id.mytext" into an integer like R.id.mytext that can be used in findViewById(R.id.myText).

这篇关于转换含有一个ID为整数ID字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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