Home>

I have created a function to search data recorded in Firebase.
I'm trying to write a code that displays an error message when the corresponding data is not in Firebase.
I'd like to add if statement and Toast inside the following source code. Please tell me what kind of code is necessary.

Applicable source code
@Override
                public void onChildAdded (@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

if {
Toast.makeText (SearchActivity.this, "There is no data of this zipcode", Toast.LENGTH_SHORT) .show ();
}
                }
  • Answer # 1

    First 1:onChildAddedis

      

    onChildAdded (DataSnapshot snapshot, String previousChildName) This method is triggered when a new child is added to the location to which this listener was added.

    It doesn't matter to search by saying

    . After adding a value, would you like to see if it was added?

    First 2: Firebase search is not good, because Firebase was not created for full text search of data ...

    If you read a node and want to display an error message appropriately if there is no data:
    Check this document:
    Read and Write Data on Android