-3

I am working on Retrofit to show list of images and i am using List to show images which is working fine.But the problem is now I want to show name and age from the same model class.

My Question is I want to use another List to show the name and age in the same adapter and set to same Recyclerview. Is this Possible?

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.VideoInfoHolder> {

    private Context context;
    private List<String> imgList= Collections.emptyList();
    private ArrayList<MyModel> myModel;

    public MyAdapter(Context context) {
        this.context = context;
    }

    @Override
    public VideoInfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_view, parent, false);
        return new VideoInfoHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final VideoInfoHolder holder, final int position) {

          Picasso.with(this).load(imgList.getImage()).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            //do what ever you want with your bitmap 
          imgView.setImageBitmap(loadedImage);///imgView is use to set the image in it
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });

        myModel= new ArrayList<>();
        for (int i = 0; i < myModel.size(); i++) {

            holder.tvName.setText(myModel.get(i).getName());
            holder.tvAge.setText(myModel.get(position).getAge());
        }


    }

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

    public class MyInfoHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public AppCompatImageView imgView;
        public AppCompatTextView tvName, tvAgee;

        public VideoInfoHolder(View itemView) {
            super(itemView);

            tvName = (AppCompatTextView) itemView.findViewById(R.id.tv_name);
            tvAge = (AppCompatTextView) itemView.findViewById(R.id.tv_age);

        }

      }

    public void notifyDataChange(List<String> myList) {
        if (!imgList.isEmpty()) {
            imgList.clear();
        }
        imgList= myList;
        notifyDataSetChanged();
    }
}
Shiva
  • 5
  • 5

1 Answers1

0

You should create your own model with image name and age.After that in first parsing just set image and use in adapter. In second time use name and age in same adapter model. In last notify adapter.

Thanks.

Yogendra
  • 4,817
  • 1
  • 28
  • 21