转换含有一个ID为整数ID字符串整数、字符串、ID

2023-09-13 00:49:58 作者:牛粪爱鲜花。

我有一个简短的问题:

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

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).

 
精彩推荐