0

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

actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
Ashu_FalcoN
  • 916
  • 2
  • 10
  • 21

1 Answers1

-1
if (weight.toString().isNullOrEmpty()){
    // proceed
}
Bucket
  • 7,415
  • 9
  • 35
  • 45
Omar Mahmoud
  • 2,902
  • 1
  • 14
  • 22