Search code examples
androidkotlintextinputlayout

How to get text from TextInputLayout in Kotlin?


I have a text input layout with id login_mobile_number, I have imported this module to stop using findViewById methods:

import kotlinx.android.synthetic.main.activity_login.*

Whenever I try to get text from the TextInputLayout by

val loginMobileNumberString:String = login_mobile_number.editText.toString()

It returns the object name instead of the string typed in it like this:

android.support.design.widget.TextInputEditText{dfdb412 VFED..CL. .F...... 0,0-888,136 #7f0800e1 app:id/textInputEditText}

Why this is occuring? What is the proper method to get string from that field?


Solution

  • You can use this;

    val loginMobileNumberString = login_mobile_number.text.toString()
    

    No need to specify as :String.