繁体   English   中英

如何在 LazyAdapter 中反转 ListView 的顺序

[英]How to reverse order of ListView in LazyAdapter

您好,我正在使用它从 SD 卡加载图像。 除了我希望颠倒列表的顺序之外,一切都运行良好。 我知道这很模糊,但希望有人可能遇到过这个适配器并且可以帮助我。 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;
    }
}

为什么不使用回收器视图和滑行? 这个库已经过时了。 要反转列表中的顺序,您应该将包含数据的列表以相反的顺序传递给您的适配器。 为您的示例检查一下: How do I reverse an int array in Java?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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