Я пытаюсь передать значение из массива в RecyclerView в другой фрагмент, чтобы позволить кнопке перенести его в другое место в зависимости от того, что говорит массив.
Когда один из параметров в ArrayList выбран, он показывает фрагмент, содержащий кнопку, поэтому, по сути, я хочу, чтобы массив содержал значение для переноса этой кнопки в другой фрагмент.
Это мой RecyclerViewAdapter. java
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
Context mContext;
List<Members> mData;
Dialog myDialog;
public RecyclerViewAdapter(Context mContext, List<Members> mData) {
this.mContext = mContext;
this.mData = mData;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v;
v = LayoutInflater.from(mContext).inflate(R.layout.item_members, parent, false);
final MyViewHolder vHolder = new MyViewHolder(v);
//Dialog ni
myDialog = new Dialog(mContext);
myDialog.setContentView(R.layout.dialog_members);
myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//This ensures that the application knows which number of the array in the recyclerview is being selected
vHolder.item_members.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView dialog_name_tv = (TextView) myDialog.findViewById(R.id.dialog_name_id);
TextView dialog_party_tv = (TextView) myDialog.findViewById(R.id.dialog_party_id);
TextView dialog_constituency_tv = (TextView) myDialog.findViewById(R.id.dialog_constituency_id);
ImageView dialog_td_img = (ImageView) myDialog.findViewById(R.id.dialog_td_img);
dialog_name_tv.setText(mData.get(vHolder.getAdapterPosition()).getName());
dialog_party_tv.setText(mData.get(vHolder.getAdapterPosition()).getParty());
dialog_constituency_tv.setText(mData.get(vHolder.getAdapterPosition()).getConstituency());
dialog_td_img.setImageResource(mData.get(vHolder.getAdapterPosition()).getPhoto());
// Toast.makeText(mContext, "TD Record No. " + String.valueOf(vHolder.getAdapterPosition()), Toast.LENGTH_SHORT).show();
myDialog.show();
}
});
return vHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
holder.tv_name.setText(mData.get(position).getName());
holder.tv_party.setText(mData.get(position).getParty());
holder.tv_constituency.setText(mData.get(position).getConstituency());
holder.img.setImageResource(mData.get(position).getPhoto());
holder.imgConstituency.setImageResource((mData.get(position).getPhotoConstituency()));
}
@Override
public int getItemCount() {
return mData.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
private LinearLayout item_members;
private TextView tv_name;
private TextView tv_party;
private TextView tv_constituency;
private ImageView img;
private ImageView imgConstituency;
public MyViewHolder(View itemView) {
super(itemView);
item_members = (LinearLayout) itemView.findViewById(R.id.members_item_id);
tv_name = (TextView) itemView.findViewById(R.id.name_members);
tv_party = (TextView) itemView.findViewById(R.id.party_members);
tv_constituency = (TextView) itemView.findViewById(R.id.constituency_members);
img = (ImageView) itemView.findViewById(R.id.img_members);
imgConstituency = (ImageView) itemView.findViewById(R.id.img_constituency);
}
}
}