简体   繁体   中英

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.

在此处输入图片说明

need

在此处输入图片说明

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

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());

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM