I am trying to save the radio button user response in Firestore under the UID. I have two choices yes and no to the question. It only works one time that the user selects a choice with a button pressed but if the user wants to change the answer it does not update (replace the old response).
I am wondering if anyone can help so that the selected response can be updated.
buttonfor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String yes = yesButton.getText().toString();
String no = yesButton.getText().toString();
Map<String, Object> user = new HashMap<>();
if (radioGroup.getCheckedRadioButtonId() == R.id.question_a1) {
user.put("I am wiling to participate", yes);
} else if (radioGroup.getCheckedRadioButtonId() == R.id.question_a2){
user.put("I am wiling to participate", no);
}
userID = fAuth.getCurrentUser().getUid();
fStore.collection("users").document(userID).set(user).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(question.this, "User Response Saved", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(question.this, "Error!", Toast.LENGTH_SHORT).show();
Log.d(TAG, e.toString());
}
});
}
});
In addition, I also tried but the response does not update in Firestore
if (yesButton.isChecked()){
user.put("I am wiling to participate", yes);
} else if (noButton.isChecked()){
user.put("I am wiling to participate", no);
}
And with update instead of set also did not work...
fStore.collection("users").document(userID).update(user).addOnSuccessListener(new OnSuccessListener<Void>()