I need your help because I'm having a hard time writing data to Firebase.
I need to create a feedback screen of my App, but the information is not being recorded in the database.
The application works fine and displays the message as if it were written, but as soon as I open the firebase there is no information at all.
My code.
mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
mRatingScale.setText(String.valueOf(v));
switch ((int) ratingBar.getRating()) {
case 1:
mRatingScale.setText("Muito Ruim");
break;
case 2:
mRatingScale.setText("Precisa de melhorias");
break;
case 3:
mRatingScale.setText("Bom");
break;
case 4:
mRatingScale.setText("Ótimo");
break;
case 5:
mRatingScale.setText("Impressionante. Eu amei isso");
break;
default:
mRatingScale.setText("");
}
}
});
mSendFeedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mFeedback.getText().toString().isEmpty()) {
Toast.makeText(ActivityFeedback.this, "Por favor, preencha a caixa de texto de feedback", Toast.LENGTH_LONG).show();
} else {
mFeedback.setText("");
mRatingBar.setRating(0);
gravarRatingBar();
Toast.makeText(ActivityFeedback.this, "Obrigado por compartilhar esse feedback", Toast.LENGTH_SHORT).show();
}
}
});
}
private void gravarRatingBar() {
final DatabaseReference ref = database.getReference("ratingbar").child("rating");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null && dataSnapshot.getValue() != null) {
float rating = Float.parseFloat(dataSnapshot.getValue().toString());
mRatingBar.setRating(rating);
}
}
@Override
public void onCancelled(DatabaseError databaseError) { }
});
mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
if (fromUser) ref.setValue(rating);
}
});
}