0

I am changing hint based on phone number and id, if user is entering number then I am programmatically setting hint to Enter 10 digits and when user enter id, the hint is Enter 5 digits Now the problem is, when I focus on TextInputEditText, the hint doesn't goes up.

<android.support.design.widget.TextInputLayout
        android:id="@+id/textinput_web_ref"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".75"
        android:textColorHint="@color/colorA">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/tv_web_input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/colorA"
            android:inputType="number"
            android:textColor="@color/colorTransparent"
            android:textColorHint="@color/colorA" />

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

code

if (title.getText().toString().contentEquals("ID")) {
    inputEditText.setHint("Enter 5 digits");
} else {
    inputEditText.setHint("Enter 10 digits");
}
Nouman
  • 31
  • 9

1 Answers1

1

Try to set hint on TextInputLayout. For example:

if (title.getText().toString().contentEquals("ID")) {
    textInputLayout.setHint("Enter 5 digits");
} else {
    textInputLayout.setHint("Enter 10 digits"); 
}

TextInputLayout is generally a layout which wraps a TextInputEditText, EditText, or descendant to show a floating label when the hint is hidden while the user inputs text. So, your hint becomes the floating label when the user is writing anything in textInputEditText.

Alok Bharti
  • 136
  • 1
  • 8