omega
omega

Reputation: 43833

How to highlight text when edittext gets focused?

In my android app, I have a bunch of edititexts that's a numeric keyboard. On the keyboard is a next key, which when clicked moves the cursor to the next edittext. How can I make it highlight the text of the new focused edit text when the next key is clicked? Basically I want to just click next, then type some new numbers which replaces the old one.

Thanks.

Upvotes: 0

Views: 2957

Answers (2)

Mike M.
Mike M.

Reputation: 39191

editText.setOnFocusChangeListener(new OnFocusChangeListener()
{
    @Override
    public void onFocusChange(View v, boolean hasFocus)
    {
        if(hasFocus)
        { 
            editText.setSelection(editText.getText().toString().length());
        }
    }
}
);

Upvotes: 1

RussVirtuoso
RussVirtuoso

Reputation: 888

Add this to your EditText on xml:

android:selectAllOnFocus="true"

Upvotes: 8

Related Questions