Ad
How To Get The Name Of Parent A+ For This Code?
I am unable to access this parent node using that code.
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(LoginActivity.this,"Login error", Toast.LENGTH_SHORT).show();
} else {
String user = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference mRef = FirebaseDatabase.getInstance().getReference();
final Query userQuery = mRef.orderByChild(user);
userQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
map.clear();
String myParentNode = dataSnapshot.getKey();
for (DataSnapshot child: dataSnapshot.getChildren()) {
String key = child.getKey().toString();
String value = child.getValue().toString();
map.put(key, value);
}
Intent intent = new Intent(LoginActivity.this, UserMapActivity.class);
intent.putExtra("bloodType",myParentNode);
startActivity(intent);
}
}
}
}
i want to get the highlighted parent from the underline child in every session
Ad
Answer
To get A+
, please use the following lines of code:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("Users");
Query query = usersRef.orderByChild(uid).equalTo(true);
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
Log.d(TAG, ds.getKey());
//Do what you need to do with your key
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
}
};
query.addListenerForSingleValueEvent(valueEventListener);
The output in the logatcat will be:
A+
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad