I have a recyclerview with radiobutton,the aim is to have a pop-up(dialogue) appear anytime the user selects the "non-appropriate" radio button, from which options would appear and based on the users selection from those options, a new activity will be opened with the info from the recyclerview.
So far, i have been able to do the dialogue and activities, but where i have an issue is getting the data from the recyclerview into the new activity.
I have read similar threads and none had the answer i need.
Pass Data from Dialog to new Activity
RecyclerView Click to pass data to new activity
Main Activity
////Firebase Adapter and related properties
FirebaseRecyclerOptions<Drugs> options = new FirebaseRecyclerOptions.Builder<Drugs>()
.setQuery(query, Drugs.class).build();
adapter = new FirebaseRecyclerAdapter<Drugs, DrugsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull DrugsViewHolder holder, final int position, @NonNull Drugs model) {
holder.setDiag1(model.getBrand());
holder.setDiag2(model.getGeneric());
holder.setDiag3(model.getDose());
holder.setDiag4(model.getFrequency1(), model.getFrequency2(), model.getDuration());
}
@NonNull
@Override
public DrugsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
////Recycler view item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.drug_display_list,viewGroup,false);///
return new DrugsViewHolder(view);
}
};
patient_drug_list.setLayoutManager(new LinearLayoutManager(this));
patient_drug_list.setAdapter(adapter);//// setting adapter
adapter.notifyDataSetChanged();
adapter.startListening();
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
adapter.notifyDataSetChanged();
}
public void rbclick(View view) {
////Activated when ever a user presses the "non-appropriate" radiobutton
AlertDialog.Builder myDialog = new AlertDialog.Builder(Review2.this);
LayoutInflater inflater = LayoutInflater.from(Review2.this);
View myview = inflater.inflate(R.layout.adr_options, null);
myDialog.setView(myview);
myDialog.show();
}
////////////////click for new option activities
//This is a switch for the adio button options that appear after the above radiobutton
public void clickers(View view) {
switch (view.getId()){
case R.id.drug_needed:
startActivity(new Intent(getApplicationContext(),Drug_needed.class));
break;
case R.id.wrong_drug:
Toast.makeText(Review2.this, "2nd", Toast.LENGTH_SHORT).show();
break;
case R.id.dose_related:
startActivity(new Intent(getApplicationContext(),Dose.class));
break;
case R.id.adverse_reaction:
startActivity(new Intent(getApplicationContext(),ADR.class));
break;
case R.id.food_interaction:
Toast.makeText(this, "yet to do", Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(Review2.this, "nothing to see", Toast.LENGTH_SHORT).show();
break;
}
}
////////////////View Holder
private class DrugsViewHolder extends RecyclerView.ViewHolder{
View mView;
DrugsViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
}
void setDiag1(String diag1){
TextView postdiag1 = mView.findViewById(R.id.brand);
postdiag1.setText(diag1);
}
void setDiag2(String diag2){
TextView postdiag2 = mView.findViewById(R.id.generic);
postdiag2.setText(diag2);
postdiag2.setTextSize(12);
}
public void setDiag3(String diag3){
TextView postdiag3 = mView.findViewById(R.id.dose);
postdiag3.setText("Dose:" + diag3);
}
public void setDiag4(String diag4, String diag5, String diag6){
TextView postdiag4 = mView.findViewById(R.id.frequency);
postdiag4.setText("Frequency:" + diag4 + " tab " + diag5+"x" + "daily for "+diag6 + "days");
}
}
Recyclerview layout(showing only the radiobuttons with onClick function)
<RadioGroup
android:id="@+id/radio_appropriate"
android:layout_below="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/appropraite"
android:layout_weight="1"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appropriate"
android:textColor="@color/cool_blue"
android:layout_margin="10dp"/>
<RadioButton
android:onClick="rbclick"
android:id="@+id/not_appropriate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="Inapropriate"
android:textColor="@color/cool_blue" />
</RadioGroup>
Below is a picture summary of what i want to do
Selecting the "non appropriate" radiobutton
Dialogue after selecting the radiobutton from recyclerview
What should happen(what am expecting)
Any ideas or suggestions or links on how i should go about it would be appreciated.