我正在创建一个用于预订的应用。 在预订历史页面,如果用户还没有预订,应该是这样的:
但是当我执行它时,它是这样的:
代码:
DocumentReference documentReference = fstore.collection("Booking").document(userID);
//if the document exists then set text and make visible, but if it doesn't exist dont be visible
//i am a beginner i set this if condition it doesn't seem to work it just sets the textviews to visible please help.
if(documentReference!=null) {
documentReference.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
//putting if else fixed crashing
if (e != null) {
Log.d("Tag", "Error:" + e.getMessage());
} else {
//pickup
mYourpickup.setVisibility(View.VISIBLE);
mYourdestination.setVisibility(View.VISIBLE);
mBook.setVisibility(View.VISIBLE);
mFirstnamelastname.setText(documentSnapshot.getString("a1 - Fullname"));
mFirstnamelastname.setVisibility(View.VISIBLE);
mMobnum.setText(documentSnapshot.getString("a2 - PhoneNo"));
mMobnum.setVisibility(View.VISIBLE);
mPincode.setText(documentSnapshot.getString("a3 - Pincode"));
mPincode.setVisibility(View.VISIBLE);
mFlatno.setText(documentSnapshot.getString("a4 - Flatno"));
mFlatno.setVisibility(View.VISIBLE);
mArea.setText(documentSnapshot.getString("a5 - Area"));
mArea.setVisibility(View.VISIBLE);
mLandmark.setText(documentSnapshot.getString("a6 - Landmark"));
mLandmark.setVisibility(View.VISIBLE);
mTown.setText(documentSnapshot.getString("a7 - Town"));
mTown.setVisibility(View.VISIBLE);
mState.setText(documentSnapshot.getString("a8 - State"));
mState.setVisibility(View.VISIBLE);
//destination
mFirstnamelastname2.setText(documentSnapshot.getString("d1 - Fullname2"));
mFirstnamelastname2.setVisibility(View.VISIBLE);
mMobnum2.setText(documentSnapshot.getString("d2 - PhoneNo2"));
mMobnum2.setVisibility(View.VISIBLE);
mPincode2.setText(documentSnapshot.getString("d3 - Pincode2"));
mPincode2.setVisibility(View.VISIBLE);
mFlatno2.setText(documentSnapshot.getString("d4 - Flatno2"));
mFlatno2.setVisibility(View.VISIBLE);
mArea2.setText(documentSnapshot.getString("d5 - Area"));
mArea2.setVisibility(View.VISIBLE);
mLandmark2.setText(documentSnapshot.getString("d6 - Landmark2"));
mLandmark2.setVisibility(View.VISIBLE);
mTown2.setText(documentSnapshot.getString("d7 - Town2"));
mTown2.setVisibility(View.VISIBLE);
mState2.setText(documentSnapshot.getString("d8 - State2"));
mState2.setVisibility(View.VISIBLE);
}
}
});
}
请在您回答此问题时尝试向我解释发生了什么,以便我学习和理解而不是复制粘贴。 谢谢:)