0

I subclassed the standard EditText widget like so

public class MyEditText extends AppCompatEditText {

    public MyEditText( Context context )
    {
        super( context );
    }

    public MyEditText( Context context, AttributeSet attribute_set )
    {
        super( context, attribute_set );
    }

    public MyEditText( Context context, AttributeSet attribute_set, int def_style_attribute )
    {
        super( context, attribute_set, def_style_attribute );
    }

    @Override
    public boolean onKeyPreIme( int key_code, KeyEvent event )
    {
        if ( event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP )
            this.clearFocus();

        return super.onKeyPreIme( key_code, event );
    }
} 

I declared this widget in my activity xml layout file like so

    <MyEditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="[enter command here]"
        android:textColorHint="#5042f442"
        android:textSize="15dp"
        android:textColor="#42f442"
        android:background="#50000000"
        android:layout_alignParentBottom="true"
        android:gravity="center|left"
        android:paddingLeft="20dp"
        android:cursorVisible="false"
        />

</RelativeLayout>

When I install the apk to my phone and run the app I get this error

android.view.InflateException: Binary XML file line #7: Error inflating class MyEditText

Not sure why there is an error inflating the custom Edit Text.

Any idea why?

Thanks

the_prole
  • 8,275
  • 16
  • 78
  • 163
  • Look further on in the stack trace. Any more relevant info than just the `InflateException`? Are you sure the `Context` you're inflating with has an `AppCompat` theme? – Mike M. Apr 20 '17 at 00:21
  • Could this line from the stack trace have something to do with error `java.lang.ClassNotFoundException: Didn't find class "android.view.MyEditText" on path: DexPathList[[zip file "/data/app/com.adafruit.bluefruit.le.connect-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]` – the_prole Apr 20 '17 at 00:28
  • 1
    Oh, yeah, I totally missed that. My bad. You need to use the fully-qualified class name for your custom `View` class in the layout; e.g., ``. – Mike M. Apr 20 '17 at 00:31
  • Thanks, if you post the answer, I'll check mark you – the_prole Apr 20 '17 at 00:36
  • Actually, this has been answered before, so I'll just mark it as a duplicate. Thanks, though. Appreciate the offer. Glad you got it working. Cheers! – Mike M. Apr 20 '17 at 00:38

0 Answers0