How to show next image on button click if I have image urls in an array?

If you have String values in your imageList array representing resource names private String imageList = { "image_wo_lbl_0", "image_wo_lbl_1", "image_wo_lbl_2" } then you can modify the loadImage method: private void loadImage(final String imagePath) { imageLoader. SetImageResource(getResources(). GetIdentifier(imagePath, "drawable", "your.application.

Package")); } If you have urls stored in the imageList array private String imageList = { "file:///somedir/IMAG0001. Jpg", "file:///otherdir/IMAG0002. Jpg", "file:///somedir/IMAG0003.

Jpg" } you can use private void loadImage(final String imagePath) { imageLoader. SetImageURI(Uri. Parse(imagePath)); } When loading images from the web (storing their urls in the imageList ): private String imageList = { "http://somedomain/IMAG0001.

Jpg", "http://otherdomain/IMAG0002. Jpg", "http://somedomain/IMAG0003. Jpg" }; ... private void loadImage(String imagePath) { try { final URL url = new URL(imagePath); final InputStream inputStream = (InputStream)url.getContent(); Drawable drawable = Drawable.

CreateFromStream(inputStream, "src"); imageLoader. SetImageDrawable(drawable); } catch (Exception e) { Log. E("Error", "loadImage", e); } } For this to work, don't forget to add the android.permission.

INTERNET permission to your application in the `androidManifest. Xml!

If you have String values in your imageList array representing resource names, private String imageList = { "image_wo_lbl_0", "image_wo_lbl_1", "image_wo_lbl_2" }; then you can modify the loadImage method: private void loadImage(final String imagePath) { imageLoader. SetImageResource(getResources(). GetIdentifier(imagePath, "drawable", "your.application.

Package")); } If you have urls stored in the imageList array private String imageList = { "file:///somedir/IMAG0001. Jpg", "file:///otherdir/IMAG0002. Jpg", "file:///somedir/IMAG0003.

Jpg" }; you can use private void loadImage(final String imagePath) { imageLoader. SetImageURI(Uri. Parse(imagePath)); } When loading images from the web (storing their urls in the imageList): private String imageList = { "http://somedomain/IMAG0001.

Jpg", "http://otherdomain/IMAG0002. Jpg", "http://somedomain/IMAG0003. Jpg" }; ... private void loadImage(String imagePath) { try { final URL url = new URL(imagePath); final InputStream inputStream = (InputStream)url.getContent(); Drawable drawable = Drawable.

CreateFromStream(inputStream, "src"); imageLoader. SetImageDrawable(drawable); } catch (Exception e) { Log. E("Error", "loadImage", e); } } For this to work, don't forget to add the android.permission.

INTERNET permission to your application in the `androidManifest. Xml!

You can use imageList exactly the same as you did in your example, just change the int declarations to String, since it is a String array. – rekaszeru May 20 at 11:20 how does your url look like? Share an item from your imageList array, please.

– rekaszeru May 20 at 14:20 You need to specify the protocol through you get the image, so insert before the paths items in your list. – rekaszeru May 21 at 5:16 thanks for the urls, please see my update for how to load images from the web. – rekaszeru May 21 at 6:27 thanks it works and I also posted my answer pls see it,it also works...but problem is I had used this and worked but now problem is that how to show button left and right of image ..means image is displaying in full width ,and in my xml file I had defined wrap_content for imageview but button is not showing on left and right how to solve this..thanks for appreciating me again.... – atul yadav May 21 at 7:13.

Rekaszeru I had used private void loadImage(String imagePath) { try { /* Open a new URL and get the InputStream to load data from it. */ URL aURL = new URL(imagePath); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap.

*/ Bitmap bm = BitmapFactory. DecodeStream(bis); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ imageLoader.

SetImageBitmap(bm); //bigView. SetImageBitmap(bm); // bigView. SetScaleType(ImageView.ScaleType.

FIT_CENTER); imageLoader. SetImageBitmap(bm); } catch (IOException e) { // i. SetImageResource(R.drawable.

Error); Log. E("DEBUGTAG", "Remote Image Exception", e); }.

Rekaszeru I had used this and worked but now problem is that how to show button left and right of image ..means image is displaying in full width ,and in my xml file I had defined wrap_content for imageview but button is not showing on left and right how to solve this..thanks for appreciating me again.... – atul yadav May 21 at 7:12 This is a good solution too! About the layout issue I'd suggest you to open a new thread, to keep StakOverflow's answers clean, focused on solving a specific issue, not serving a single member. This way others might find it helpful as well.

And ask the question providing the layout, and specifying exactly, how you need the buttons to be lied out: may they overlap the image area, or the image should be in the area between the two buttons? Thank you! – rekaszeru May 21 at 7:31.

You should take only one Imageview and set image using setImageResource properties and increase the countervalue when click on next button . You can also use imageswitcher control for solving this problem.

You can refer to this SO question. Every time your press you have to call that method and change the URL by passing the next element in the array.

Next image on button click is shown (without quotes):. Show next image on button click.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions