0

Description of the widget :

The widget is composed of a listview. Each item of this listview has differents attributes :

  • title
  • imageUrl
  • price
  • ...

Problem :

With the url of each item, i have write a little code to load image from web, images is well displayed in my listview but when i want to scroll my listview, all item desappeared and the system try to load other images corresponding the item which is displayed.

Code sample :

Here is the code of my getViewAt() method where i perform theses actions :

public RemoteViews getViewAt(int position) {

    WidgetItem item = mWidgetItems.get(position);
    // We construct a remote views item based on our widget item xml file, and set the
    // text based on the position.

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext);
    String theme = settings.getString("choixtheme", "default");

    if (theme.equals("default")) {
        rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item_default);
    }

    if (item.urlImage != "") {
            URL url = new URL(urlImage);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            myBitmap = BitmapFactory.decodeStream(input);   
    }       

    // Return the remote views object.
    return rv;
}
Wawanopoulos Ertz
  • 135
  • 1
  • 2
  • 7

1 Answers1

0

You can refer this:http://www.developerfusion.com/article/145373/android-listviews-with-dynamic-data/

and

Lazy load of images in ListView

Hope it helpful!

Community
  • 1
  • 1
charmpeach
  • 58
  • 1
  • 8