在另一个活动中显示适配器类中的图像

时间:2019-07-14 15:15:15

标签: android android-recyclerview recycler-adapter

我在适配器的imageview中显示图像时遇到问题。图像视图用于其他活动,如下所示:

RecyclerView rvAddItems;
medToHomeAdapter.setOnDataItemClickListener(new DataItemClickPrescriptionButon() {
        @Override
        public void onDataClick(int position) {
                selectImage(position);
        }
    });
    rvAddItems.setLayoutManager(mLayoutManager);
    rvAddItems.setItemAnimator(new DefaultItemAnimator());
    rvAddItems.setAdapter(medToHomeAdapter);

我从selectImage()函数从图库中选择我的图像。我的适配器类如下:

public class MedToHomeAdapter extends RecyclerView.Adapter<MedToHomeAdapter.MyViewHolder> {
public List<MedToHomeModel> medToHomeModelList;
DataItemClickPrescriptionButon onDataItemClickListener;

public MedToHomeAdapter(List<MedToHomeModel> medToHomeModels) {
    this.medToHomeModelList = medToHomeModels;
}
public void setOnDataItemClickListener(DataItemClickPrescriptionButon onDataItemClickListeners){
    this.onDataItemClickListener = onDataItemClickListeners;
}


@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.prescription_button_items, parent, false);

    return new MyViewHolder(itemView);    }

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
    MedToHomeModel checkInModel = medToHomeModelList.get(position);
    holder.spinRVAddItems.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onDataItemClickListener.onDataClick(position);
        }
    });
}

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

public class MyViewHolder extends RecyclerView.ViewHolder {
    public ImageView spinRVAddItems;
    TextView txtPrescription;
    public MyViewHolder(View itemView) {
        super(itemView);
        spinRVAddItems =  itemView.findViewById(R.id.spinRVAddItems);

    }
}

}

setOnDataItemClickListener的界面如下:

public interface DataItemClickPrescriptionButon {
   void onDataClick(int position);
    }

每次我在活动上单击添加按钮时,适配器都会弹出一个新的图像视图。选择图像后,我想在适配器的图像视图中显示它。我做不到。可以帮我一下吗?

0 个答案:

没有答案