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

爷,独闯天下 提交于 2019-12-12 10:22:25

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/13271957/how-to-set-focus-to-the-text-after-the-hint-in-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!