如何在android中的{Integer [] image}字符串。

时间:2013-10-02 12:11:21

标签: java android

public Integer[] imgs = new Integer[]{ 
R.drawable.ic_launcher,R.drawable.ic_launcher

};

String s_img = "R.drawable.img_test";

我想要

  • imgs [0] = s_img

  • imgs [0] == R.drawable.img_test

  • true !!

我该怎么办?

5 个答案:

答案 0 :(得分:1)

试试这个:

s_img = "img_test";//not "R.drawable.img_test" just the name of the image
if(getResources().getIdentifier(s_img, "drawable", getPackageName()) == imgs[0]){
   return true;
}else{
   return false;
}

答案 1 :(得分:0)

你想要一组drawables,对吧?

Integer[] drawables = {R.drawable.image1, R.drawable.image2, ....};

您可以通过以下方式访问值:

drawables[0] == R.drawable.image1

drawables[1] == R.drawable.image2

然后你就把它们圈起来了。

答案 2 :(得分:0)

用于比较对象不使用" == "

"R.drawable.img_test".equals(Integer.toString(imgs[0]));

答案 3 :(得分:0)

将它们放入Enum而不是数组。

答案 4 :(得分:0)

告诉我这正是你需要与否,我想我会得到你需要的东西。

public Integer[] imgs = new Integer[]{ 
    R.drawable.ic_launcher,R.drawable.ic_launcher
                 };


    String s_img;

     s_img = Integer.toString(x);