How do you check if an EditText is empty? input type number
package com.example.www.myappl
Here is the full example with explanation.
//init the edittext
val etMessage = findViewById(R.id.et_message) as EditText
//init the button
val btnClick = findViewById(R.id.btn_click) as Button
btnClick.setOnClickListener{
//read value from EditText to a String variable
val msg: String = etMessage.text.toString()
//check if the EditText have values or not
if(msg.trim().length>0) {
Toast.makeText(applicationContext, "Message : "+msg, Toast.LENGTH_SHORT).show()
}else{
Toast.makeText(applicationContext, "Please enter some message! ", Toast.LENGTH_SHORT).show()
}
}
Try this:
if(TextUtils.isEmpty(editText.getText().toString())){
//Do
}
Hey I am using like this in kotlin
val input = editText?.text.toString().trim()
if (input.isNullOrBlank()) {
//Your code for blank edittext
}
Hope this will help you..let me know if any issue....