Siruk Viktor
Siruk Viktor

Reputation: 514

How to set focus to the text after the hint in EditText?

I'm interested in you can set the focus to the text after the prompt to EditText? If no such attribute for xml layout? At the moent I still looked like this.

enter image description here

need

enter image description here

EDIT :
The fastest and working answer given Asok
I also found a similar way:
EditText.append("60"); // 60 or your text in EditText

Upvotes: 0

Views: 1140

Answers (2)

dudel
dudel

Reputation: 692

A hint is no real text, it disappears after the user types something. Assuming the cursor would be at the end of the hint what behaviour would you expect when the user presses a button and the hint disappears?

What you can do is set a default text in the XML via

android:text="60"

or in code via

editText.setText("60");

and on focus jump to the end of the EditText via

editText.setSelection(editText.getText().length());

Upvotes: 3

jnthnjns
jnthnjns

Reputation: 8925

If I understand correctly you are looking to place the cursor behind the hint text, if this is correct then it is not possible, you'll have to remove hint and use setText instead, like so:

EditText et = (EditText)findViewById(R.id.sixtyseconds);
et.setText("60");
et.setSelection(et.getText().length());

Upvotes: 0

Related Questions