Reputation: 61
public class Userprofile extends Fragment {
private FragmentUserprofileBinding binding;
FirebaseAuth firebaseAuth;
FirebaseDatabase db= FirebaseDatabase.getInstance();
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentUserprofileBinding.inflate(inflater, container, false);
View root = binding.getRoot();
View view = inflater.inflate(R.layout.fragment_userprofile, container, false);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
String x= phoneNoClass.getMobileNoOfDoctor();
binding.logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firebaseAuth.signOut();
}
});
DatabaseReference roat=db.getReference("DoctorData").child("+919937336406");
roat.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (task.isSuccessful()){
Toast.makeText(getContext(), "updating....."+task.getException(), Toast.LENGTH_SHORT).show();
String uname=String.valueOf(task.getResult().child("name").getValue());
binding.UserName.setText(uname);
}else {
Toast.makeText(getContext(), "unable"+task.getException(), Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
}
Upvotes: 1
Views: 46
Reputation: 138824
According to your comment:
yes the result is showing in the log but not in the app.
The problem isn't related to Firebase, it's a problem related to the way you are using data binding. So the simplest solution is to use View's findViewById(int id) method to refer to your UserName
TextView.
Upvotes: 1