0

Here is my code, and there is no problem in XML all the ids of the views are correct

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val button: Button = findViewById(R.id.button)
        val stringInTextField:EditText = findViewById(R.id.bill)
        button.setOnClickListener(View.OnClickListener{
        val userInput = stringInTextField.text.toString()
        if (userInput.isEmpty) {
            Toast.makeText(this, "Please Enter the Bill", Toast.LENGTH_SHORT).show()
        }
    })
}
AlexTa
  • 5,133
  • 3
  • 29
  • 46

2 Answers2

1

There is an error in your code, since String class has no property isEmpty but a method isEmpty(). So fix that error in order to make it work:

if (userInput.isEmpty()) { // Here is the fix
    Toast.makeText(this, "Please Enter the Bill", Toast.LENGTH_SHORT).show()
}
AlexTa
  • 5,133
  • 3
  • 29
  • 46
0

You can try this code if (!userInput.equals(""))

hungcuiga1
  • 114
  • 2
  • 11