Проблема с определением пользовательского: inputType для ClearableEditText

1

Я пытаюсь использовать custom:inputType="text" custom:inputType="phone". помогите мне, edit_text всегда настраивает defvalue. но есть проблема с значением индекса, если я использую format="integer" тогда

R.java

дает ошибку.

здесь main.xml

<com.example.ClearableEditText.ClearableEditText
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    custom:hintText="@string/name"
                    custom:inputType="text" />
</LinearLayout>

attr.xml где я использую формат inputType как целое число

<declare-styleable name="ClearableEditText">
    <attr name="hintText" format="string" />
    <attr name="inputType" format="integer">
       <flag name="text" value="0x00000001" />
        <!--
         Can be combined with <var>text</var> and its variations to
         request capitalization of all characters.  Corresponds to
         {@link android.text.InputType#TYPE_TEXT_FLAG_CAP_CHARACTERS}.
        -->
       <flag name="phone" value="0x00000003" />
        <!--
         For entering a date and time.  Corresponds to
         {@link android.text.InputType#TYPE_CLASS_DATETIME} |
         {@link android.text.InputType#TYPE_DATETIME_VARIATION_NORMAL}.
        -->
    </attr>
</declare-styleable>

это код класса ClearableEditText

void initViews(Context context, AttributeSet attrs) {

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.ClearableEditText, 0, 0);

    try {
        hintText = a.getString(R.styleable.ClearableEditText_hintText);
        inputType=a.getResourceId(R.styleable.ClearableEditText_inputType, android.text.InputType.TYPE_CLASS_TEXT);
    } finally {
        a.recycle();
        initViews();
    }
}

void initViews() {
    inflater = (LayoutInflater) getContext().getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.second, this, true);
    edit_text = (EditText) findViewById(R.id.clearable_edit);
    btn_clear = (Button) findViewById(R.id.clearable_button_clear);
    btn_clear.setVisibility(RelativeLayout.INVISIBLE);
    edit_text.setHint(hintText);
    edit_text.setInputType(inputType);
    }
  • 0
    Основная проблема заключается в том, что edit_text.setInputType (inputType); устанавливает по умолчанию android.text.InputType.TYPE_CLASS_TEXT.
Теги:

1 ответ

1
Лучший ответ

Я нашел ошибку. lol, я использовал этот getResourceId (int, int); но attr.xml я объявил его целым числом.

inputType=a.getResourceId(R.styleable.ClearableEditText_inputType,android.text.InputType.TYPE_CLASS_TEXT);

Но беря его как целое, фиксируем каждый.

inputType=a.getInteger(R.styleable.ClearableEditText_inputType,android.text.InputType.TYPE_CLASS_TEXT);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню