What’s the standard way of getting an Int value from an EditText ? (Android Kotlin/Java)

  android, kotlin

I am now in the process of cleaning my code.
I have an EditText view that receives an input of type "number".
In my code, I use this code to get the value:

            val host: Int = binding.serverInputBox.text.toString().toInt()

As you may already know, the EditText text values are of type Editable, and it just seemed like a long reach to translate it twice, first to String, then second to Int.

My question is: Is this the most efficient way to do it? Or there are better alternatives even slightly ?

Source: Android Questions

LEAVE A COMMENT