0

I have a address edit text and many other text box which automatically populates data from DB when requested.

In the address Edit Text. I have multiline enabled. what happens here is when the user starts typing the text is entered from the beginning and not from the end. I am not sure why this is happening.

E.g if I have a text "79 Edge Drive" already populated from DB. After clicking edit when focused on address - I type something now. this is how it is typed: "California79 Edge Drive"

I tried the following:

addText.requestFocus();
addText.setSelection(addText.length());

Not working? Anything else that can get to the last length automatically?

TheDevMan
  • 5,656
  • 12
  • 67
  • 133

3 Answers3

5

Your question is basically the same as this one from stack Overflow:

Place cursor at the end of text in EditText

where marqss said to do this:

EditText et = (EditText)findViewById(R.id.inbox);
et.setSelection(et.getText().length());
Community
  • 1
  • 1
HalR
  • 10,678
  • 5
  • 43
  • 74
1

You have to use

addText.setSelection(addText.getText().length());

Or else you are getting the length of the View element, not the text in the TextView.

Also, please search for your question before you post, others have asked, and have been answered on the same topic.

Matt Clark
  • 24,947
  • 16
  • 62
  • 114
0

try this

addText.setSelection(addText.getText().length() );
ElefantPhace
  • 3,743
  • 3
  • 18
  • 36