Skip to content

Instantly share code, notes, and snippets.

@alfianyusufabdullah
Created September 5, 2019 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfianyusufabdullah/f918fe6f5c5c99c3249b6778fbfa45f4 to your computer and use it in GitHub Desktop.
Save alfianyusufabdullah/f918fe6f5c5c99c3249b6778fbfa45f4 to your computer and use it in GitHub Desktop.
val inputLength = edtLength.text.toString().trim { it <= ' ' }
val inputWidth = edtWidth.text.toString().trim { it <= ' ' }
val inputHeight = edtHeight.text.toString().trim { it <= ' ' }
if (inputLength.isEmpty()) {
edtLength.error = "Field ini tidak boleh kosong"
return
}
if (inputWidth.isEmpty()) {
edtWidth.error = "Field ini tidak boleh kosong"
return
}
if (inputHeight.isEmpty()) {
edtHeight.error = "Field ini tidak boleh kosong"
return
}
val length = toDouble(inputLength)
val width = toDouble(inputWidth)
val height = toDouble(inputHeight)
if (length == null) {
edtLength.error = "Field ini harus berupa nomer yang valid"
return
}
if (width == null) {
edtWidth.error = "Field ini harus berupa nomer yang valid"
return
}
if (height == null) {
edtHeight.error = "Field ini harus berupa nomer yang valid"
return
}
val volume = length * width * height
tvResult.text = volume.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment