Passing Firebase data from RecyclerView to another Custom Dialog with RecyclerView - Android

37 Views Asked by At

I'm a newbie and I cannot pass the data of a recyclerview from a custom dialog to the current clicked recyclerview inside the activity.

I made the TextView from my Adapter static to try and pass it on but it ends up on the last data of the recyclerview in the activity.

This is from the first recyclerview where you can see it on the MainActivity.class

public class RecyclerWithDiaAdapter extends RecyclerView.Adapter<RecyclerWithDiaAdapter.ViewHolder> {

Context context;
ArrayList<RWDModel> stringArrayList;

public static Dialog dialog;

public RecyclerWithDiaAdapter(Context context, ArrayList<RWDModel> stringArrayList) {
    this.context = context;
    this.stringArrayList = stringArrayList;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.item_recy_with_dia, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    RWDModel positional = stringArrayList.get(position);

    holder.header_title.setText(positional.header);
    holder.detail_title.setText(positional.detail);
}

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

public static class ViewHolder extends RecyclerView.ViewHolder {

    static TextView header_title;
    TextView detail_title;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);

        header_title = itemView.findViewById(R.id.header_title);
        detail_title = itemView.findViewById(R.id.detail_title);

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog(detail_title.getContext());
            }
        });
    }
}

private static void showDialog(Context context) {
    dialog = new Dialog(context);
    dialog.setCancelable(false);
    dialog.setContentView(R.layout.dialog_recycler);

    Button btndialog = (Button) dialog.findViewById(R.id.btndialog);
    btndialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dialog.dismiss();
        }
    });

    RecyclerView recyclerView = dialog.findViewById(R.id.recycler);
    AdapterRe adapterRe = new AdapterRe(context, RecyWithDia.strings);
    recyclerView.setAdapter(adapterRe);
    recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));

    dialog.show();
   }
}

And this is the custom dialog with recyclerview

public class AdapterRe extends RecyclerView.Adapter<AdapterRe.ViewHolder> {

private Context context;
private String[] myImageNameList;

public AdapterRe(Context context, String[] myImageNameList) {
    this.context = context;
    this.myImageNameList = myImageNameList;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.item_recycler, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    holder.name.setText(myImageNameList[position]);
    holder.title.setText("For ");
}

@Override
public int getItemCount() {
    return myImageNameList.length;
}

public static class ViewHolder extends RecyclerView.ViewHolder {

    TextView name;
    TextView title;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);

        name = (TextView) itemView.findViewById(R.id.name);
        title = (TextView) itemView.findViewById(R.id.title);

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                RecyclerWithDiaAdapter.dialog.dismiss();
            }
        });
    }
  }
}
0

There are 0 best solutions below