How to set error in Edittext if mobile number already exists in the Firebase database. If the user enters the existed number the values gets updated so anyone can give existed number and change the data. I want to display Toast or error if mobile already exist.
public void onClick(View v) {
String location = actv.getText().toString();
String dob = age.getText().toString();
String name1 = name.getText().toString();
String mobile1 = mobile.getText().toString();
String blood1 = blood.getSelectedItem().toString();
String combo = name1 + "," + mobile1 + "," + location + "," + dob;
if (blood1.equals("") || mobile1.equals("") || location.equals("Tap to detect") || dob.equals("") ) {
Toast.makeText(MainActivity.this, "Please fill all the details.", Toast.LENGTH_SHORT).show();
} else {
mFirebaseDatabase.child("users").child(blood1).child(mobile1).setValue(combo);
Toast.makeText(MainActivity.this, "Donor Added", Toast.LENGTH_SHORT).show();
Intent home = new Intent(MainActivity.this, Home.class);
startActivity(home);
finish();
}
}
});