在我的drawable文件夹中,我有: decouvrir_0_0.jpg, decouvrir_0_1.jpg, decouvrir_0_2.jpg, decouvrir_1_0.jpg, decouvrir_1_1.jpg, ....
我会创建一个动态画廊,其中包含以意图i给出的前缀(例如:decouvrir_0,decouvrir_1,...)开头的drawable: getResources()。getIdentifier(i.getStringExtra(“IdDecouvrir”)。toString()
=> 1个前缀= 1个画廊
=>我将新的jpgs放在drawable = new gallery
中我在API中找到了Integer []的示例mImageIds = {R.drawable.decouvrir_0_0,........但我不想使用array.xml
一个想法还是不可能?
我尝试了很多这个论坛的答案,没有任何作用......
答案 0 :(得分:0)
boolean Res_exists = true;
int k=1;
do{
String Resou = getIntent().getExtras().getString("categorie").toString()+"_" + k;
int test = getResources().getIdentifier(Resou, "drawable", getPackageName());
if (test != 0)
{ Toast.makeText(getBaseContext(),mImageIds[0].toString(), Toast.LENGTH_LONG).show(); // displays an Int, array OK
//mImageIds[1] = test; //try 1
//mImageIds[k] = getResources().getIdentifier(Resou, "drawable", getPackageName()); // try 2 problem is here
//mThumbIds[k] = getResources().getIdentifier(Resou+"_t", "drawable", getPackageName()); // try 3
k++;
//break;
}
else
{Res_exists = false; break;}
}
while (Res_exists = true);
private Integer[] mThumbIds = {R.drawable.decouvrir_0_0_t};
private Integer[] mImageIds = {R.drawable.decouvrir_0_0};