Kotlin text validation
First of all, make attention - your code twice convert and check value. Suppose it's not efficient. Another tiny problem - 1280 and 1500 values is not change prefs.mtuSize…

My code:

class MainActivity : AppCompatActivity() {
    val TAG = MainActivity::class.simpleName.toString()

    private val defaultSize = 1500
    private var prefsMtuSize: Int = defaultSize

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val textMTU = findViewById&lt;EditText&gt;(R.id.textMTU)

        // Extension function
        textMTU.addTextChangedListener { text -&gt;
            val textToInt = try { text.toInt() } catch (e: NumberFormatException) { 0 }
            if (textToInt in 1280..1500) { // 1280 &lt;= textToInt &lt;= 1500
                textMTU.error = null
                prefsMtuSize = textToInt
            } else {
                textMTU.error = getString(R.string.errorTroubleshoot)
                prefsMtuSize = defaultSize
            }
            Log.i(TAG, "prefsMtuSize = $prefsMtuSize")
        }
    }
}

private fun EditText.addTextChangedListener(testFunction: (text: String) -&gt; Unit) {
    addTextChangedListener(object : TextWatcher {
        override fun afterTextChanged(s: Editable?) {
            testFunction(s.toString())
        }
        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { }
        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { }
    })
}