从EditText中获取数值

问题描述 投票:0回答:1

我想从firebase登录,但我无法从EditText中获取值。

我的代码

var name = findViewById<EditText>(R.id.signName)
var email = findViewById<EditText>(R.id.signEmail)
var password = findViewById<EditText>(R.id.signPass)
val mEmail = email.text.toString()
val mPass = password.text.toString()

Log.d("eee", "data $mEmail $mPass")

btnOK.setOnClickListener {
    var auth = FirebaseAuth.getInstance()
    auth.createUserWithEmailAndPassword(mEmail, mPass)
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                Log.d("sign", "create:success")
                val intent = Intent(applicationContext, MainLoginActivity::class.java)
                startActivity(intent)
            } else {
                Log.w("sign", "create:failure", task.exception)
                Toast.makeText(this, "Authentication failed.", Toast.LENGTH_SHORT).show()
                name.setText("")
                email.setText("")
                password.setText("")
                name.requestFocus()
            }
        }
}

日志中什么都没有出现。

日志是:2020-05-17 *** Deee:数据。

错误是:java.lang.IllegalArgumentException。给定的字符串为空或无效

kotlin android-edittext
1个回答
1
投票

试着把这两行放在onClickListener里面。

mEmail = email.text.toString()
mPass = password.text.toString()
© www.soinside.com 2019 - 2024. All rights reserved.