-1

I am newbie to Android Development. I have created a helloandroidappwithlogin its completely working fine but just one thing where I am stuck is how to get the text selected

I have set the Username slot as Username So if a user tap/click on it, it should the username and start writing his username

to make things easy to understand i am attaching a screenshot

enter image description here

this is what I want to achieve

when a user tap on username it should do like this

Krunal
  • 77,632
  • 48
  • 245
  • 261
Amir Ali
  • 11
  • 7
  • 1
    Possible duplicate of [Select all text inside EditText when it gets focus](https://stackoverflow.com/questions/4669464/select-all-text-inside-edittext-when-it-gets-focus) – Ali Momen Sani Jun 23 '17 at 11:48
  • EditText et=(EditText)findViewById(R.id.edit); int startSelection=et.getSelectionStart(); int endSelection=et.getSelectionEnd(); String selectedText = et.getText().toString().substring(startSelection, endSelection); try this – Gowthaman M Jun 23 '17 at 11:51

2 Answers2

2

You can try like this

android:selectAllOnFocus="true"
Piyush
  • 18,895
  • 5
  • 32
  • 63
Sunil P
  • 3,698
  • 3
  • 13
  • 20
0

You could try a OnClickListener() This is from this question.

editText.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        editText.setSelection(editText.getText().length() - 1, 0);
    }
}
Marjorie Pickard
  • 109
  • 1
  • 2
  • 10