LoginSignup
0
0

More than 1 year has passed since last update.

TextInputLayoutにxmlでテキストを指定したらエラーが出た

Posted at

やりたかったこと

TextInputLayout を使ったテキストフィールドにテキストを指定したかった

やったこと

こんな感じにxmlで TextInputLayout にテキストを指定してみた

<com.google.android.material.textfield.TextInputLayout
    ~
    android:text="@{viewModel.user.name}">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

出たエラー

Cannot find a setter for < com.google.android.material.textfield.TextInputLayout android:text > that accepts parameter type 'java.lang.String'

If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.

TextInputLayout では android:textString 型では受け付けていませんよ、というエラー

解決策

android:textTextInputEditText の方に書きましょう

<com.google.android.material.textfield.TextInputLayout
    ~>

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
      android:text="@{viewModel.user.name}" />

</com.google.android.material.textfield.TextInputLayout>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0