简体   繁体   中英

How to set List<String> into RecyclerView adapter for ImageView on Android

In my application i want show images into RecyclerView Adapter .
I write below codes, but not show me any images into ImageView.

My Adapter codes :

public class DetailMiniGalleryAdapter extends RecyclerView.Adapter<DetailMiniGalleryAdapter.ViewHolder> {
    private List<String> model;
    private Context context;

    public DetailMiniGalleryAdapter(Context context, List<String> model) {
        this.context = context;
        this.model = model;
    }

    @Override
    public DetailMiniGalleryAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row_detail_mini_gallery, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(DetailMiniGalleryAdapter.ViewHolder viewHolder, int i) {

        Glide.with(context)
                .load(Constants.SERVER + model)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(viewHolder.listRow_detailMiniGalleryImg);
        Log.e("galleryImages", model+"");
    }

    @Override
    public int getItemCount() {
        return model.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView listRow_detailMiniGalleryImg;

        public ViewHolder(View view) {
            super(view);

            listRow_detailMiniGalleryImg = view.findViewById(R.id.listRow_detailMiniGalleryImg);
        }
    }
}

My images url in LogCat :

/galleryImages: [/img/ps/1.png, /img/ps/2.png, /img/ps/3.png, /img/ps/4.png, /img/ps/5.png]

I fill adapter with this code in mainActivity :

miniGalleryAdapter = new DetailMiniGalleryAdapter(getActivity(), detail.getImage());

But when use this code : .load(Constants.SERVER + model.get(0)) show me image but just show 1image ! i want show all of images .

how can i it?

Instead of using model directly in load , use model.get(i)

 Glide.with(context)
            .load(Constants.SERVER + model.get(i)) //< i is position of item
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(viewHolder.listRow_detailMiniGalleryImg);

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