0

I have the following code to get URL from HTML file using jsoup and save in array:

Element table2 = document.select("TABLE").get(1);
for (Element td : tr.select("td")){
                        Element img = td.select("img").first();
                        if (img == null){
                            continue;
                        }
                    String imgRelPath = img.attr("src");
                    images.add("http://hostname.com"+imgRelPath);
                    }

                }
                objImages = images.toArray();

The array has:

http://hostname.com/hobbit/gifs/static/green.gif
http://hostname.com/hobbit/gifs/static/green.gif
http://hostname.com/hobbit/gifs/static/clear.gif
http://hostname.com/hobbit/gifs/static/clear.gif
http://hostname.com/hobbit/gifs/static/green.gif
http://hostname.com/hobbit/gifs/static/red.gif
http://hostname.com/hobbit/gifs/static/green.gif
http://hostname.com/hobbit/gifs/static/green.gif
http://hostname.com/hobbit/gifs/static/green.gif
http://hostname.com/hobbit/gifs/static/green.gif

No I need get all images from url and put into imageView one after the other. Any idea?

Thanks in advance.

EDIT:

I'm calling Picasso.with in Async Task on onPostExecute in MainActivity:

@Override
protected void onPostExecute(Void result) {
    ImageView estados = (ImageView) findViewById(R.id.estados);
    Picasso.with(MainActivity.this).load("http://salesianoscarmona.com/nuevo/templates/rt_modulus_j15/images/icons/icon-crank.png").into(estados);
mProgressDialog.dismiss();
}

I have the import in the header:

import com.squareup.picasso.Picasso;
2
  • store image in local and retrieve it using path Commented Jul 30, 2015 at 8:57
  • Use listview with custom view. Commented Jul 30, 2015 at 8:59

2 Answers 2

1

there str several great libraries that download and set image to ImageView from url:

http://square.github.io/picasso

or

https://github.com/bumptech/glide

Both are great. With picasso you can easily set url to image view and it will do the job example

Picasso.with(context).load("http://hostname.com/hobbit/gifs/static/green.gif").into(imageView);

Hope this helps

Sign up to request clarification or add additional context in comments.

5 Comments

I made an example like: Picasso.with(MainActivity.this).load("http://www.casitreinta.com/img/noselect_menu.png").into(estados); where estados is an imageView and I get this error: Could not find method com.squareup.picasso.Picasso.with, referenced from method activities.monitorapp.MainActivity$Update.onPostExecute I don't know why :(
Can you post here where are you calling from Picasso.with method. It is async task on post execute yes ? please copy some code. Have you imported Picasso properly ?
Maybe it is because of wrong context. MainActivity.this may be wrong on that situation, maybe getbasecontext or getapplicationcontext will work for you
Y tried with getApplicationContext and getBaseContext and the result is the same, error: ` VFY: unable to resolve static method 8119: Lcom/squareup/picasso/Picasso;.with (Landroid/content/Context;)Lcom/squareup/picasso/Picasso;` java.lang.NoClassDefFoundError: com.squareup.picasso.Picass at activities.monitorapp.MainActivity$Update.onPostExecute(MainActivity.java:294)
It is hard to tell what problem is about.maybe second lib (glide) will be good for you. It is almost the same
0

Use Universal image loader for downloading images asynchronously.

 http://github.com/nostra13/Android-Universal-Image-Loader

The Library itself has a sample code to download image.you may refer it.. After downloading library add library with your project and insert the below code at necessary place

String final_url="www.google.com/.....";
ImageView image;

ImageLoader  imageloader = ImageLoader.getInstance();

imageloader.init(ImageLoaderConfiguration.createDefault(context));

DisplayImageOptions options; = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.ic_empty)
                .showImageOnFail(R.drawable.ic_error)
                .resetViewBeforeLoading(true).cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
                .cacheInMemory(true)
                .displayer(new FadeInBitmapDisplayer(300)).build();
imageloader.displayImage(final_url, image);

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.