check if username exists inside firebase database : <p>Am trying to check if a username exists from a database by calling the function checkifUsernameExists(username) within an if statement. the problem is firebase's built function called</p>

<pre><code> public void onDataChange(@NonNull DataSnapshot dataSnapshot)
</code></pre>

<p>cannot return a boolean value. What can i do?</p>

<pre><code>    mCreateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String username = musername.getText().toString();
            String email = mEmail.getText().toString();
            String password = mPassword.getText().toString();

            if (TextUtils.isEmpty(username) || TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
                Toast.makeText(registerActivity.this, "Cannot sign you in. Please check the form and try again",
                        Toast.LENGTH_SHORT).show();
            } else if (password.length() &lt; 6) {
                Toast.makeText(registerActivity.this, "Password must be at least 6 characters",Toast.LENGTH_LONG).show();
            } else if (email_exists == true) {
                Toast.makeText(registerActivity.this, "Email already exists",Toast.LENGTH_LONG).show();
            } else if (checkifUsernameExists(username)) {
                Toast.makeText(registerActivity.this, "Username already exists", Toast.LENGTH_LONG).show();
            } else {
                message.setTitle("Registering user");
                message.setMessage("Pleases wait while we create your account");
                message.setCanceledOnTouchOutside(false);
                message.show();
                //registerUser(username, email, password);
            }

        }
    });
}
</code></pre>

<pre><code>
    private boolean checkifUsernameExists(String username) {
        Query usernameQuery = FirebaseDatabase.getInstance().getReference().child("users").orderByChild("username").equalTo(username);
        usernameQuery.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                if (dataSnapshot.getChildrenCount() &gt; 0) {

                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
    }

</code></pre>
