0

I am creating an android application for image sharing.In mainactivity one gridview that shows images from Arraylist<String> named img .when i clicked on any image then another activity called that have only one ImageView that shows image that i select on mainactivity, but i am not able set image in ImageView using ImageView.setImageResource(img.get(currentImage)) method.where img is ArrayList of string type.

any help will be appreciate.

3
  • Create ArrayList of Drawable and pass position to another Activity and load Image from Drawable ArrayList as per position .. Commented Nov 25, 2014 at 6:47
  • Need to convert your image to Bitmap and need to use setImageBitmap. Commented Nov 25, 2014 at 6:48
  • Try to pass selected image path to another activity using intent put extra Commented Nov 25, 2014 at 6:48

2 Answers 2

1

You can create an ArrayList of Integers and then easily assign the image to the imageview:

Example code:

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(R.drawable.your_image);
imageView.setImageResource(Integer.intValue(list.get(0)));
Sign up to request clarification or add additional context in comments.

2 Comments

imageView.setImageResource(Integer.intValue(list.get(0))); it give me error : Non-static method 'intvalue()' cannot be referenced from a static context
it's intValue() and not intvalue(), try again :)
0

Within the array will store the names of the pictures, like R.drawable.img1 , R.drawable.img2... Then, use the command:

ImageView img;
img.setImageResource(R.drawable.img1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.