androidandroid-edittexttextviewandroid-custom-viewandroid-attributes

Reusing 'inputType' attribute from TextView in custom view


I'm trying to reuse the 'android:inputType' attribute from TextView in my custom view, but the error I get is:

String types not allowed (at 'inputType' with value 'textMultiline').

I have referred to the solution at https://stackoverflow.com/a/10361617/313042

The attr file contains:

<declare-styleable name="MyEditText">
    <attr name="android:inputType"/>
</declare-styleable>

The MyEditText.java is:

int n = typedArray.getIndexCount();
for (int i = 0; i < n; i++) {
    int attr = typedArray.getIndex(i);

    switch (attr) {
        case R.styleable.MyEditText_android_inputType:
            inputTypes = typedArray.getInt(attr, EditorInfo.TYPE_NULL);
            break;

    }
}

and the layout file contains:

<com.example.MyEditText
  android:id="@+id/met"
  style="@style/MyStyle"
  android:layout_marginLeft="0dp"
  android:layout_marginRight="0dp"
  android:layout_marginTop="12dp"
  android:inputType="textMultiline" />

Is there any way I can solve this issue? Thanks.


Solution

  • Your typo textMultiline must be textMultiLine.

    Please see supported android:inputType via xml in this link