I want to use Firebase real-time database in my app project. I want to check if the word which is filled by user exists in database.
Here is my database ss:
Here is my code:
private Button button;
private FirebaseDatabase database;
private DatabaseReference mRef;
private TextView tvResult;
private EditText et1;
et1=(EditText) findViewById(R.id.et1);
button=(Button) findViewById(R.id.btn);
tvResult=(TextView) findViewById(R.id.tvResult);
database=FirebaseDatabase.getInstance();
mRef=database.getReference();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
city=et1.getText().toString();
Query query = mRef.child("app").orderByChild("cities").equalTo(city);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
// dataSnapshot is the "issue" node with all children with id 0
String get= dataSnapshot.getValue().toString();
tvResult.setText(get);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
}
});
As I said, user fills edittext and after clicking a button, I want to show written city in textview if there is in database.