Guest User

Untitled

a guest
Jan 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import java.lang.reflect.Field;
  2.  
  3. String imageName ="image";
  4. R.drawable rDrawable = new R.drawable();
  5. Field field;
  6. try {
  7. field = rDrawable.getClass().getField(imageName);
  8. resId=field.getInt(rDrawable);
  9. } catch (SecurityException e) {
  10. // TODO 自動生成された catch ブロック
  11. e.printStackTrace();
  12. } catch (NoSuchFieldException e) {
  13. // TODO 自動生成された catch ブロック
  14. e.printStackTrace();
  15. } catch (IllegalArgumentException e) {
  16. // TODO 自動生成された catch ブロック
  17. e.printStackTrace();
  18. } catch (IllegalAccessException e) {
  19. // TODO 自動生成された catch ブロック
  20. e.printStackTrace();
  21. }
  22.  
  23. Bitmap image = BitmapFactory.decodeResource(getResources(), resId);
Add Comment
Please, Sign In to add comment