-3

我正在改造以显示图像列表,并且我正在使用 List 来显示工作正常的图像。但现在的问题是我想从同一个模型类中显示名称和年龄。

我的问题是我想使用另一个列表在同一个适配器中显示名称和年龄,并设置为相同的 Recyclerview。这可能吗?

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();
    }
}
4

1 回答 1

0

您应该使用图像名称和年龄创建自己的模型。之后在第一次解析中设置图像并在适配器中使用。第二次在同一适配器模型中使用名称和年龄。在最后通知适配器。

谢谢。

于 2018-06-01T09:59:56.770 回答