Okay, here are some updates that I guess will explain the problem better:
好的,這里有一些更新,我想這將更好地解釋問題:
I'm trying to do this following tasks with firebase database:
我正在嘗試使用firebase數據庫執行以下任務:
Permission
value is allow
or not in the firebase database https://example.firebaseio.com/Users/Permission
如果驗證了用戶的電子郵件地址,請檢查firebase數據庫中的Permission值是否允許https://example.firebaseio.com/Users/Permission
Permission: "allow"
, then make the profileAllow
layout visible. Else, make the profileVarified
layout visible.如果Permission:“allow”,則使profileAllow布局可見。否則,使profileVarified布局可見。
profileNotVarified
layout visible.如果未驗證電子郵件,請使profileNotVarified布局可見。
My problem is if the email of the user is not verified, it makes the profileNotVarified
layout visible perfectly, but when the email is verified, the logic doesn't work. Whether the Permission
value is allow
or else, it doesn't make any layout visible. My guess is that it is not getting any value form the database. (I have tried making all the layouts visible or going to another activity for verified emails but it doesn't do anything. It just displays a blank layout).
我的問題是如果未驗證用戶的電子郵件,它會使profileNotVarified布局完美可見,但是當驗證電子郵件時,邏輯不起作用。無論Permission值是否允許,它都不會使任何布局可見。我的猜測是它沒有從數據庫中獲得任何價值。 (我已嘗試使所有布局可見或轉到另一個活動以驗證電子郵件,但它沒有做任何事情。它只顯示一個空白布局)。
This is my activity where I guess the problem is:
這是我的活動,我猜問題是:
private void loadUserInformation() {
final FirebaseUser user = mAuth.getCurrentUser();
if (user.isEmailVerified()) {
Firebase AllUserPermission = new Firebase("https://example.firebaseio.com/Users/Permission");
AllUserPermission.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String myStrign = dataSnapshot.getValue(String.class);
if (myStrign.equals("allow")) {
profileAllow.setVisibility(View.VISIBLE);
profileVarified.setVisibility(View.GONE);
profileNotVarified.setVisibility(View.GONE);
} else {
profileAllow.setVisibility(View.GONE);
profileVarified.setVisibility(View.VISIBLE);
profileNotVarified.setVisibility(View.GONE);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {}
});
} else {
profileAllow.setVisibility(View.GONE);
profileVarified.setVisibility(View.GONE);
profileNotVarified.setVisibility(View.VISIBLE);
}
}
For reference, I'm also attaching the xml and the database structure here as well.
作為參考,我也在這里附加了xml和數據庫結構。
This is my activity_profile.xml
:
這是我的activity_profile.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ProfileActivity">
<RelativeLayout
android:id="@+id/profileNotVarified"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/imageView"
android:layout_marginStart="59dp"
android:layout_marginTop="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Not varified" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/profileVarified"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Varified" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/profileAllow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Allowed" />
</RelativeLayout>
</RelativeLayout>
This is my database structure:
這是我的數據庫結構:
0
AllUserPermission.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String myStrign = dataSnapshot.getValue(String.class);
if (myStrign.equals("allow")) {
profileVarified.setVisibility(View.VISIBLE);
profileNotVarified.setVisibility(View.GONE);
}
else {
profileNotVarified.setVisibility(View.VISIBLE);
profileVarified.setVisibility(View.GONE);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
I hope this will help.
我希望這將有所幫助。
0
To solve this, please use the following lines of code:
要解決此問題,請使用以下代碼行:
if (user.isEmailVerified() && myStrign.equals("allow")) {
profileVarified.setVisibility(View.VISIBLE);
profileNotVarified.setVisibility(View.GONE);
} else {
profileNotVarified.setVisibility(View.VISIBLE);
profileVarified.setVisibility(View.GONE);
}
Edit:
private void loadUserInformation() {
final FirebaseUser user = mAuth.getCurrentUser();
Firebase AllUserPermission = new Firebase("https://smartpedi-rimikri.firebaseio.com").child("Users").child("Permission");
AllUserPermission.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String myStrign = dataSnapshot.getValue(String.class);
if (user.isEmailVerified() && myStrign.equals("allow")) {
profileVarified.setVisibility(View.VISIBLE);
profileNotVarified.setVisibility(View.GONE);
} else {
profileNotVarified.setVisibility(View.VISIBLE);
profileVarified.setVisibility(View.GONE);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {}
});
}
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/06/22/720ea78a7d6a6518fc11367bbb444918.html。