第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

檢查用戶名是否存在于 firebase 數(shù)據(jù)庫中

檢查用戶名是否存在于 firebase 數(shù)據(jù)庫中

拉丁的傳說 2022-12-21 10:57:56
我試圖通過在 if 語句中調(diào)用函數(shù) checkifUsernameExists(username) 來檢查數(shù)據(jù)庫中是否存在用戶名。問題是 firebase 的內(nèi)置函數(shù)稱為 public void onDataChange(@NonNull DataSnapshot dataSnapshot)不能返回布爾值。我能做什么?    mCreateBtn.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View view) {            String username = musername.getText().toString();            String email = mEmail.getText().toString();            String password = mPassword.getText().toString();            if (TextUtils.isEmpty(username) || TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {                Toast.makeText(registerActivity.this, "Cannot sign you in. Please check the form and try again",                        Toast.LENGTH_SHORT).show();            } else if (password.length() < 6) {                Toast.makeText(registerActivity.this, "Password must be at least 6 characters",Toast.LENGTH_LONG).show();            } else if (email_exists == true) {                Toast.makeText(registerActivity.this, "Email already exists",Toast.LENGTH_LONG).show();            } else if (checkifUsernameExists(username)) {                Toast.makeText(registerActivity.this, "Username already exists", Toast.LENGTH_LONG).show();            } else {                message.setTitle("Registering user");                message.setMessage("Pleases wait while we create your account");                message.setCanceledOnTouchOutside(false);                message.show();                //registerUser(username, email, password);            }        }    });}
查看完整描述

1 回答

?
蕭十郎

TA貢獻1815條經(jīng)驗 獲得超13個贊

如果數(shù)據(jù)庫中不存在用戶名,則使 checkifUsernameExists() 方法無效并在其中調(diào)用 registerUser() 方法。


mCreateBtn.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View view) {


        String username = musername.getText().toString();

        String email = mEmail.getText().toString();

        String password = mPassword.getText().toString();


        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {

            Toast.makeText(registerActivity.this, "Cannot sign you in. Please check the form and try again",

                    Toast.LENGTH_SHORT).show();

        } else if (password.length() < 6) {

            Toast.makeText(registerActivity.this, "Password must be at least 6 characters",Toast.LENGTH_LONG).show();

        } else if (email_exists == true) {

            Toast.makeText(registerActivity.this, "Email already exists",Toast.LENGTH_LONG).show();

        } else {

            checkifUsernameExists(username, email, password);

        }


    }

});


private void checkifUsernameExists(final String username, final String email, final String password) {


    Query usernameQuery = FirebaseDatabase.getInstance().getReference().child("users").orderByChild("username").equalTo(username);

    usernameQuery.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override

        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            if (dataSnapshot.exists()) {

                // the username is already in the database

                Toast.makeText(registerActivity.this, "Username already exists", Toast.LENGTH_LONG).show();

            }else {

                message.setTitle("Registering user");

                message.setMessage("Pleases wait while we create your account");

                message.setCanceledOnTouchOutside(false);

                message.show();

                registerUser(username, email, password);

            }

        }


        @Override

        public void onCancelled(@NonNull DatabaseError databaseError) {


        }

    });

}


查看完整回答
反對 回復(fù) 2022-12-21
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號