如何在覆盖函数之外为变量分配值?

时间:2019-04-24 15:59:57

标签: android scope google-cloud-firestore

如何将值保存在覆盖函数之外的变量中,并保存它,以便在需要时可以使用它 代码:

private boolean matchLogin(){
    final boolean[] matchLogin = new boolean[1];
    db.collection("Supervisor").addSnapshotListener(this, new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            if (e != null) {
                return;
            }
            for (@android.support.annotation.Nullable QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                if(documentSnapshot.getString("Username").equals(textUser.getEditText().getText().toString().trim())){
                    if (documentSnapshot.getString("Password").equals(textPassowrd.getEditText().getText().toString().trim())) {
                        matchLogin[0] = true;
                        Log.d("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrorrrrrrrrrrrrrrrrrrrrrr  ===== " , "Login");
                        KeySuper = documentSnapshot.getId();
                        break;
                    } else {
                        Log.d("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrorrrrrrrrrrrrrrrrrrrrrr  ===== " , "Password");
                        matchLogin[0] = false;
                        break;
                    }
                }else{
                    Log.d("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrorrrrrrrrrrrrrrrrrrrrrr  ===== " , "User");
                    matchLogin[0] = false;
                    break;
                }
            }
        }
    });
    Log.d("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrorrrrrrrrrrrrrrrrrrrrrr  ===== " , String.valueOf(matchLogin[0]));
    if(matchLogin[0]){
        return true;
    }else{
        return false;
    }
}

这是我要对其进行更改并希望在具有正确值的同一函数中使用的变量

final boolean[] matchLogin = new boolean[1];

0 个答案:

没有答案