The output not showing in the text view and image. I input toast to see if data is being fetch in the showdata, but it show null.
FirebaseUser user = mAuth.getCurrentUser();
userid = user.getUid();
myRef= FirebaseDatabase.getInstance().getReference().child("User").child(userid);
Toast.makeText(Account.this, myRef.toString(), Toast.LENGTH_SHORT).show();
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Showdata(dataSnapshot);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(Account.this, "Error", Toast.LENGTH_SHORT).show();
}
});
private void Showdata(DataSnapshot dataSnapshot) {
for(DataSnapshot ds:dataSnapshot.getChildren()) {
String name = ds.child("name").getValue(String.class);
String address= ds.child("address").getValue(String.class);
String contact = ds.child("contact").getValue(String.class);
String profilepic = ds.child("profilepic").getValue(String.class);
Toast.makeText(Account.this, name, Toast.LENGTH_SHORT).show();
//display
P_name.setText(name);
P_number.setText(contact);
P_address.setText(address);
url = profilepic;
}
Glide.with(Account.this /* context */)
.load(url)
.into(P_pic);
progressdialog.dismiss();
}
The Firebase database
elbert rivas :
Try this. \n\nmyRef.addValueEventListener(new ValueEventListener() {\n @Override\n public void onDataChange(@NonNull DataSnapshot dataSnapshot) {\n // You can access the values here, no need to loop. Store it on your custom object, in this case User\n\n User user = dataSnapshot.getValue(User.class);\n Toast.makeText(Account.this, user.getName(), Toast.LENGTH_SHORT).show();\n }\n\n @Override\n public void onCancelled(@NonNull DatabaseError databaseError) {\n Toast.makeText(Account.this, \"Error\", Toast.LENGTH_SHORT).show();\n }\n});\n",
2018-11-12T06:38:11