Slideshow with images from Urls

Asked

Viewed 252 times

5

I was developing a slideshow loading images from Urls I found a library developed by a Russian, the Universal Image Loader, however this slideshow will be used in the application in the version of tablet. In the mobile version I use a listview.

The only problem is that the slideshow was giving error in version 3.0 which is precisely the minimum version for tablet.

I make the connection with the webservice and bring from the database the Urls that change constantly, then I use the pager and the library classes.

    String[] imageUrls = new String[logos.size()];//logos é um List<String> que contem as urls
    imageUrls = (String[]) logos.toArray(imageUrls);
    //String[] imageUrls = bundle.getStringArray(Extra.IMAGES);
    int pagerPosition = bundle.getInt(Extra.IMAGE_POSITION, 0);

    if (savedInstanceState != null) {
        pagerPosition = savedInstanceState.getInt(STATE_POSITION);
    }

    options = new DisplayImageOptions.Builder()
        .showImageForEmptyUri(R.drawable.stub)
        .showImageOnFail(R.drawable.stub)
        .resetViewBeforeLoading(true)
        .cacheOnDisc(true)
        .imageScaleType(ImageScaleType.EXACTLY)
        .bitmapConfig(Bitmap.Config.RGB_565)
        .considerExifParams(true)
        .displayer(new FadeInBitmapDisplayer(300))
        .build();

    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new ImagePagerAdapter(imageUrls));
    pager.setCurrentItem(pagerPosition);

Is there any other way to make a slideshow or some alternative, for example a grid well structured uploading images from Urls?

inserir a descrição da imagem aqui

Picture of the error that is giving

  • 1

    Post the error so we can help. NOTE: you can use the Universal Image Loader inside Listview as well.

  • I use the UIL in a slide show including Froyo (2.2) without any problem. Post the error and we can help you.

2 answers

1


NetworkOnMainThreadException occurs when the app tries to do some network operation on the main thread (the one that runs the interface).

This Exception was introduced into Honeycomb to prevent time-consuming operations from occurring on the main thread which would consequently crash the interface.

A quick solution is to disable Strictmode (which generates Exception):

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy)

But I don’t recommend this type of approach because it would hurt the user experience and could even cause an ANR.

One best solution would look for where it is performing the network operation and place this piece of code within a AsyncTask. I would guess that the stretch you take the information from the webservice would cause the problem. A second kick would be within the Adapter in the section where you upload the image, but I believe that Universalimageloader already does network operations in a separate Thread.

0

In the Twitter Bootstrap has exactly what you need. Take a look there. It’s self-explanatory.

  • 3

    Welcome! Even if this link is a good suggestion, this answer will not be valid if one day the link crashes. So, because it’s important for the community to have content right here, you’d better respond with more complete answers. Can you elaborate more your answer? A summary of the content of the link would help a lot! Learn more on this item in our Community FAQ: Answers that only contain links are good?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.