2012-02-08 47 views
3

私の質問は、アンドロイドのsetImageResource()のdrawableフォルダからイメージIDを変更する方法です。 私の描画可能なフォルダがicon9.pngするicon0.pngが含まれていると私は動的にこのsetImageResource()でdrawableのidを動的に変更する方法

ImageView iV3; 
iV3 = (ImageView) findViewById(R.id.imageView3); 
iV3.setImageResource(R.drawable.icon + speed_Arr[2]); 

speed_Arr [2]が0から任意の値が含まれている使用して画像ビューでこれらの画像を変更したい - 9 をしかし、これは、画像を変更didntは。 Plzは私を助けます。 はお待ちしております。

答えて

2
public static int getIdentifier(Context context, String name) 
{ 
    return context.getResources().getIdentifier(name.substring(0, name.lastIndexOf(".")), "drawable", context.getPackageName()); 
} 

上記のコードは、name StringからリソースIDを返します。

0

int res = getResources()。getIdentifier( "< packageName:drawable/imageName>" "、null、null); あなたのiV3でこの解像度を使用してください。

関連する問題