With ViewBinding in place, wiring up a click listener is direct:
binding.submitButton.setOnClickListener {
val nameInput = binding.nameEditText.text.toString()
if (nameInput.isBlank()) {
binding.errorText.text = "Please enter your name"
} else {
binding.greetingText.text = "Hello, $nameInput!"
}
}
A few things worth noting: .text on an EditText returns an Editable, not a plain String — hence .toString(). isBlank() checks for empty or whitespace-only input, which is usually what you want for form validation rather than just checking isEmpty().
Showing quick feedback with Toast
Toast.makeText(this, "Saved!", Toast.LENGTH_SHORT).show()
Toasts are meant for brief, non-blocking confirmations — not for anything the user must read carefully or respond to.
- Image
- SKU
- Rating
- Price
- Stock
- Availability
- Add to cart
- Description
- Content
- Weight
- Dimensions
- Additional information