0

R.drawable を使用する代わりに、独自のプロパティで drawable フォルダーから drawable を取得したい

どうすればこれを達成できますか?

public void updateLanguageImg(String img)
 {


      Bitmap myBitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.);
               // i want retrieve the img String here
      ImageView imageV = (ImageView) findViewById(R.id.imageLangue);
      imageV.setImageBitmap(myBitmap);

 }

どうもありがとうございました

4

1 に答える 1

1

私が質問を正しく理解し、メソッドで受け取ったパラメーターに従って、文字列名でリソースを呼び出したい場合、それが正しい場合は、これがあなたがしなければならないことです:

"context.getResources().getIdentifier("bitmapName","folderName",this.class.getPackageName())"

ここで、folderName は ("raw"、"drawable" など...)

これは、すでに持っている identifierNumber を返します。代わりに、次のようなメソッドを使用できます。

int id = context.getResources().getIdentifier("bitmapName","folderName",this.class.getPackageName();

ビットマップ myBitmap = BitmapFactory.decodeResource(this.getResources(), id);

よろしく!

于 2013-03-18T23:41:43.470 に答える