简体   繁体   中英

How to reverse order of ListView in LazyAdapter

Hello I am using this to load images from SD card. Everything works well except that I wish to reverse the order of the list. I know this is rather vague but hopefully someone might have come across this adapter and can help me. https://github.com/thest1/LazyList/tree/master/src/com/fedorvlasov/lazylist

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class LazyAdapter extends BaseAdapter {

    private final String[] data;

    private static LayoutInflater inflater = null;
    public ImageLoader imageLoader;

    public LazyAdapter(Activity a, String[] d) {
        // Declare variables
        data = d;
        inflater = (LayoutInflater) a
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader = new ImageLoader();
    }

    public int getCount() {
        return data.length;

    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (convertView == null)
            vi = inflater.inflate(R.layout.gridview_item, null);
        // Locate the ImageView in item.xml
        ImageView image = vi.findViewById(R.id.image);
        // Capture position and set to the ImageView
        imageLoader.DisplayImage(data[position], image);
        return vi;
    }
}

Why not use a recycler view and glide? This library is outdated. To reverse order in a list, you should pass a list with data in reverse order to your adapter. Check this for your example: How do I reverse an int array in Java?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM