'Get text of TextInputLayout from MaterialDesigns in Kotlin
The basic code that I've seen in other posts don't seem to do the trick. It doesn't recognize the text saying Unresolved reference: text
val name = binding.etName.text.toString()
This is my XML where I have the etName, I have also try to put the etName id tag in the TextInputLayout just in case
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_marginTop="15dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/name"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#0B0B0B"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="20dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>```
Solution 1:[1]
Just use
textInputLayout.editText?.text?.toString() ?: ""
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel |
