I have an EditText set up for user input. As soon as the user types any character I want that to trigger a floating label to rise above the EditText line. What is best method to see when user has typed in the first character on the EditText line? TextWatcher? Others?
partial Activity file:
...
private ListenerEditText cListenerEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cardviewinput);
cListenerEditText = (ListenerEditText) findViewById(R.id.CEditText);
cTextInputLayout = (TextInputLayout) findViewById(R.id.ToDo_text_input_layout);
cListenerEditText.requestFocus();
cListenerEditText.setHint("To Do");
partial layout xml file:
...
<android.support.design.widget.TextInputLayout
android:id="@+id/ToDo_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.example.jdw.fourthscreen.ListenerEditText
android:id="@+id/CEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textCapSentences|textNoSuggestions"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textColorHighlight="#30D5C8"
android:singleLine="true"
android:maxLength="51"
android:imeOptions="actionNext|flagNoExtractUi"
android:layout_marginBottom="3dp"
android:nextFocusDown="@+id/DEditText" >
</com.example.jdw.fourthscreen.ListenerEditText>
</android.support.design.widget.TextInputLayout>
To monitor and/or control text input, we usually use TextWatcher
or InputFilter
.
For your case, I believe TextWatcher
is the right way to do.