gpt4 book ai didi

android - 无法从edittext获取数据,Android Kotlin

转载 作者:行者123 更新时间:2023-12-02 13:42:20 25 4
gpt4 key购买 nike

尝试从edittext获取数据时,我得到了空数据
有我的代码

class LoginActivity : AppCompatActivity() {
lateinit var etUsername : EditText
lateinit var etPassword : EditText
var username = ""
var password = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
etPassword = findViewById(R.id.tanggalLahir) as EditText
etUsername = findViewById(R.id.nomerInduk) as EditText
username = etUsername.text.toString()
password = etPassword.text.toString()

buttonLogin.setOnClickListener() {
if (username.isEmpty()){
Log.d("User", "Username = $username")
nomerInduk.error = "Nomor Induk Kosong!"
return@setOnClickListener
}

if (password.isEmpty()){
Log.d("User", "Password = $password")
tanggalLahir.error = "Tanggal Lahir Kosong!"
return@setOnClickListener
}

login(username,password)
}


}

而且当我 checkin 日志时
image check log

我已经将edittext更改为textinputedittext,但仍然相同

最佳答案

class LoginActivity : AppCompatActivity() {
lateinit var etUsername : EditText
lateinit var etPassword : EditText
var username = ""
var password = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
etPassword = findViewById(R.id.tanggalLahir) as EditText
etUsername = findViewById(R.id.nomerInduk) as EditText


buttonLogin.setOnClickListener() {
username = etUsername.text.toString()
password = etPassword.text.toString()
if (username.isEmpty()){
Log.d("User", "Username = $username")
nomerInduk.error = "Nomor Induk Kosong!"
return@setOnClickListener
}

if (password.isEmpty()){
Log.d("User", "Password = $password")
tanggalLahir.error = "Tanggal Lahir Kosong!"
return@setOnClickListener
}

login(username,password)
}


}

关于android - 无法从edittext获取数据,Android Kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62301446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com