我似乎无法将文本放入TextView。数据来自Firestore数据库。当我运行它时,TextView为空并返回null。以下是我到目前为止所做的事情。有人可以看看吗?您可以在这里看到我的数据库结构:[数据库结构图片] [1]
public class ProfileFragment extends Fragment {
TextView firstNameText, age;
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
firstNameText = rootView.findViewById(R.id.profile_firstName);
age = rootView.findViewById(R.id.profile_age);
getUserInfo();
return rootView;
}
public void getUserInfo() {
db.collection("Users").document(mAuth.getCurrentUser().getEmail()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot documentSnapshot = task.getResult();
String firstName = documentSnapshot.getString("Firstname");
Log.d(TAG, "Printing docData: " + documentSnapshot.getData());
firstNameText.setText(firstName);
}
}
});
}
}
答案 0 :(得分:0)
我猜是
mAuth.getCurrentUser().getEmail()
是这里的问题。尝试将用户的电子邮件放入字符串
#!/bin/sh
cd $1
然后替换
{{1}}
具有UID。