SlideShow with images from URLs

5

I was developing a slideshow uploading images from URLs I found a library developed by a Russian, the Universal Image Loader , but this slideshow will be used in the app in the tablet version. In the mobile version I use a listview .

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

I make the connection to webservice and I bring in the URLs that constantly change, then I use the pager and 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 well-structured grid uploading images from URLs?

Image of the error you are giving

    
asked by anonymous 30.01.2014 / 18:00

2 answers

1

NetworkOnMainThreadException occurs when the app tries to perform some network operation on the Main Thread (to which the interface runs).

This exception was introduced in Honeycomb to prevent slow operations on the main thread, which would then crash the interface.

One quick solution is to disable StrictMode (which generates Exception):

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

But I do not recommend this approach, as it would undermine the user experience and could even cause an ANR.

A best solution would look for where you are performing the network operation and put that code snippet inside a AsyncTask . I would have guessed that the snippet you get the information from the webservice would be the cause of the problem. A second kick would be within Adapter in the portion where you load the image, but I believe UniversalImageLoader already does the network operations on a separate Thread.

    
05.02.2014 / 02:25
0

No Twitter Bootstrap has exactly what you need. Take a look there. It is self-explanatory.

    
03.02.2014 / 19:23