I have 170 images in the drawable folder in my android app. I have one activity displaying all of them. What is want to do is to pass the clicked imageview to another activity (Zoom_activity) where the user can zoom it and play around with it. How do I achieve it?
All the images are 500x500px. So I can't think of decoding them into Bitmaps and passing Btmaps via Intent. Please suggest a better and simple way to do it! I have already had a look at the other answers here on SO but none of them solved my problem.
Here is my code:
Activity_1.java
Intent startzoomactivity = new Intent(Activity_one.this, Zoom_Image.class);
String img_name = name.getText().toString().toLowerCase(); //name is a textview which is in refrence to the imageview.
startzoomactivity.putExtra("getimage", img_name);
startActivity(startzoomactivity);
Zoom_Activity.java
Intent startzoomactivity = getIntent();
String img_res = getIntent().getStringExtra("getimage");
String img_fin = "R.drawable."+img_res;
img.setImageResource(Integer.parseInt(img_fin));
Error: App force closes
Please help me solve this problem!
Thanks!
What you are trying is wrong. You can not convert
"R.drawable.name"
withInteger.parseInt
. Integer.parseInt is expecting something like"100"
. You should useto retrieve the resources id you are looking for
Use
getResources().getIdentifier
to load image from Drawable in ImageView as:Integer.parseInt()
only works for strings like "1" or "123" that really contain just the string representation of an Integer.What you need is find a drawable resource by its name.
This can be done using reflection:
Or using
Resources.getIdentifier()
: