silent_coder14
silent_coder14

Reputation: 583

how to dynamically set the url in Universal Image Loader?

I am using Universal Image Loader that I found here. In this case, the url of the images is set statically or preset in String[] IMAGES. What I wanted is to make it more dynamic, say it is coming from the URL. (http://site.com/myfile.xml). I am done with parsing the XML but now my problem is setting it in Constant class in UIL. Is there any way to set the IMAGES dynamically? am I in the right direction? (parsing the xml and saving it in the ArrayList and convert it in to String[] array.)

Upvotes: 0

Views: 367

Answers (2)

May13ank
May13ank

Reputation: 548

I had a similar requirement and this is how I accomplished it :

I have one Async task which get the urls of the images from a url . So essentially it return me JSON string with list of urls. Once that request is complete , I have a listener which notifies my Fragment to update the List view.

The Async task returns a list of strings which I add to list being used by the adapter.

//Code in Async task

@Override
        protected void onPostExecute(List<String> result) {
            if (null != mClient)
                mClient.close();
            //TODO
                //Constants.IMAGES = result.toArray(new String[result.size()]);
            Constants.IMAGES.addAll(result);
                Log.i("IMAGES", IMAGES.toString());
                if (mTheListener != null && firstCallFlag ) {
                    firstCallFlag = false;
                    mTheListener.GotoNextScreen();
                }else{
                dataUpdateListener.dataUpdated(result);
            }
        }

//Code in the fargment

public void dataUpdated(List<String> data) {
        // TODO Auto-generated method stub
        imageUrls.addAll(data);
        mAdapter.notifyDataSetChanged();
    }

Upvotes: 0

Manmeet Singh Batra
Manmeet Singh Batra

Reputation: 467

After parsing the xml, in getView() of your adapter use ArrayList.get(position) instead of String[position]

Upvotes: 1

Related Questions