How can I check weather plaintext text is empty or not?
When the user inputs their weight in the plaintext area, On button click event I need to perform validation and show results on text area,
When I give some valid inputs the code works as expected
But when I don't give any input the App force stops
Here is the code
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var weight = editText.text //store input from plaintext to variable
button.setOnClickListener { //on click event for button..
//textView3.text=weight
if ( /* how to check here */ ) // condition here
{
textView2.text="Give some inputs plz :-" //
}
else
{
var res = findWeight(weight.toString().toDouble())
textView2.text= "your weight on mars is" + " " +res.toString()
}
}
}
fun findWeight(userWeight: Double): Double {
return userWeight * marsGrav
}
Please see the kotlin code when there is no input it should say "Please enter some input"
What can I put in the if
condition to check if the user input is empty?
Thank You