11

Looks like TextInputLayout just doesn't work inside ViewPager.

The error is:

Error inflating class android.support.design.widget.TextInputLayout

Appcompat and Design library added. Theme is correct.

I use PageAdapter to inflate and populate ViewPager.

The TextInputLayout view inflates just fine in all other parts of the application.

The layout I inflate for the ViewPager.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
      android:id="@+id/edit_text"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="My Edit Text" />

  </android.support.design.widget.TextInputLayout>

</LinearLayout>
comrade
  • 4,590
  • 5
  • 33
  • 48
Eugene
  • 59,186
  • 91
  • 226
  • 333

3 Answers3

0

Use this

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat">

you have also to extend your class with AppCompatActivity instead of Activity

Harry Sharma
  • 2,190
  • 2
  • 15
  • 41
0

You should try a few things to fix the problem.

  • extend your activity from AppCompatActivity
  • extend your (dialog)fragment from android.support.v4.app.Fragment.
  • use latest version of design library.
  • Instead of using EditText, use android.support.v7.widget.AppCompatEditText. For example:

        <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:errorEnabled="true">
    
                        <android.support.v7.widget.AppCompatEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="First Name"
                            android:inputType="textPersonName"
                            android:singleLine="true" />
    
        </android.support.design.widget.TextInputLayout>
    
Frank
  • 12,010
  • 8
  • 61
  • 78
0

I had the same issue and none of the above solutions worked for me. Finally, I switched PagerAdapter to FragmentStatePagerAdapter and implemented the whole thing with Fragment.

You can refer to this link for the reference.

For my experiment, I tweaked the demo and inserted TextInputLayout inside it's ViewPager and everything worked perfectly.

Name is Nilay
  • 2,743
  • 4
  • 35
  • 77