无法解决' updateUI'火力

时间:2017-06-12 04:28:13

标签: android firebase

我正在尝试通过firebase使用电子邮件和密码对用户进行身份验证。但它显示无法解析updateUI(用户)。 这是代码的这一部分。

public void OnContinue(View view) {
    if(hasClickedCountinueOnce){
        EditText emailTextBox = (EditText)findViewById(R.id.email);
        String user = userNAAME.getText().toString();
        String passwordText = password.getText().toString();
        String email = emailTextBox.getText().toString();
        //todo manage new account here
        if(!user.isEmpty() && !passwordText.isEmpty() ){
            mAuth.createUserWithEmailAndPassword(email, passwordText)
                    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                // Sign in success, update UI with the signed-in user's information
                                Log.d("SignInFailed", "createUserWithEmail:success");
                                FirebaseUser user = mAuth.getCurrentUser();
                                updateUI(user);
                            } else {
                                // If sign in fails, display a message to the user.
                                Log.w("SignInFailed", "createUserWithEmail:failure", task.getException());
                                Toast.makeText(SignUP.this, "Authentication failed.",
                                        Toast.LENGTH_SHORT).show();
                                updateUI(null);
                            }
                        }
                    });
        }
    }
}

6 个答案:

答案 0 :(得分:7)

代码来自Firebase Quickstart-Android项目。这就是它的作用。你可以实现类似的东西:

function ajax_function() { ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
    jQuery(".category_nav").click(function() {
    var cat= jQuery(this).data("category"); // get the category of the post when clicked the navigation

    var data = {
        'action': 'ajax_perform.php',//create a php file to do the wp_query to get the result of passed category value.
        'postcat': cat
    };

    jQuery.post(ajaxurl, data, function(response) {

    });

    });
});
</script> <?php
}
add_action( 'admin_footer', 'ajax_function' );

答案 1 :(得分:1)

您必须在代码中定义updateUI()。它不包含在firebase API中。

答案 2 :(得分:0)

您的身份验证编码正常。

成功登录后 FirebaseUser user = mAuth.getCurrentUser(); 的目的是什么?

要获得当前用户,您必须在成功登录后实施 Auth Change Listner

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
//Replace above details with your real server deatils

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

(使用不同的变量名称)

答案 3 :(得分:0)

如果我使用您在上面分享的有限代码正确地解决您的问题,则函数调用&#34; updateUI&#34; refred here(https://firebase.google.com/docs/auth/android/password-auth)是你必须自己编写的调用/函数来更新你的UI元素,而@BobSnyder在这里提到了参考代码的链接(https://github.com/firebase/quickstart-android/blob/master/auth/app/src/main/java/com/google/firebase/quickstart/auth/EmailPasswordActivity.java#L209

答案 4 :(得分:0)

private void updateUI(@Nullable GoogleSignInAccount account){         if(account!= null){             mStatusTextView.setText(getString(R.string.signed_in_fmt,account.getDisplayName()));

        findViewById(R.id.sign_in_button).setVisibility(View.GONE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
    } else {
        mStatusTextView.setText(R.string.signed_out);

        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
    }
}

答案 5 :(得分:0)

您需要在MainActivity中编写自己的自定义UpdateUI方法,并编写代码,说明当用户以if(user!=null).等条件登录时​​应用程序应执行的操作