Android unloads list images

Please excuse my English, I am French!

So I have a little question ... Do you know a clean way to export images as a list? I want to display images for visible items and to free up memory, unload images to other items ...

Maybe in OnScrollListener?

Thank!

+3


source to share


2 answers


ListView uses your items as converted. Thus, you only have 2 or 3 items more than you actually see. You don't need to upload these images. It's actually better not to do this, because it will slow down your application.

An important part:



@Override
public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) ctx
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.your_item, null);
        }

  // set images on view
}

      

+1


source


In fact, it is ListView

designed in such a way that the user does not need to worry about loading and unloading his data.

You provide Adapter

that contains all the data (elements), and you add this Adapter

to his ListView

, which, in turn, knows how to manage those elements - basically it downloads only those elements of the adapter, are visible to the user of the phone.



There are several built-in adapters, for example, SimpleCursorAdapter

which are generally sufficient for simple needs. But if you want more advanced usability, you would like to write your own adapter, which is actually not that hard. In this tutorial you can read about writing your own adapter: http://www.ezzylearning.com/tutorial.aspx?tid=1763429

Also you can read more about ListView

in Android documentation: http://developer.android.com/guide/topics/ui/layout/listview.html

+2


source







All Articles