Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Field;
- String imageName ="image";
- R.drawable rDrawable = new R.drawable();
- Field field;
- try {
- field = rDrawable.getClass().getField(imageName);
- resId=field.getInt(rDrawable);
- } catch (SecurityException e) {
- // TODO 自動生成された catch ブロック
- e.printStackTrace();
- } catch (NoSuchFieldException e) {
- // TODO 自動生成された catch ブロック
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO 自動生成された catch ブロック
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO 自動生成された catch ブロック
- e.printStackTrace();
- }
- Bitmap image = BitmapFactory.decodeResource(getResources(), resId);
Add Comment
Please, Sign In to add comment