我进行了编码,但似乎无法从数据库中检索数据。我不确定出了什么问题。我做了编码。我的Logcat下没有显示任何错误。所以我不确定我的代码有什么问题。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_account, container, false);
tv_name=view.findViewById(R.id.tv_name);
tv_email=view.findViewById(R.id.tv_email);
tv_gender=view.findViewById(R.id.tv_gender);
tv_home=view.findViewById(R.id.tv_home);
tv_phone=view.findViewById(R.id.tv_phone);
//ini
firebaseAuth = FirebaseAuth.getInstance();
currentUser = firebaseAuth.getCurrentUser();
databaseReference = FirebaseDatabase.getInstance().getReference("Customer");
userID = currentUser.getUid();
//For Retrieve Information
databaseReference.child("Customer").child(firebaseAuth.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.d( TAG, "onDataChange :" +dataSnapshot);
if (dataSnapshot.getValue() !=null){
Customer cust = dataSnapshot.getValue(Customer.class);
tv_name.setText(cust.name);
tv_email.setText(cust.email);
tv_gender.setText(cust.gender);
tv_home.setText(cust.home_address);
tv_phone.setText(cust.telephone_number);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
return view;
}