1

I know it maybe looks a simple question but it really annoying me, I have an Activity contains 3 "EditText", and when I lunch that activity it the cursor start in second one "EditText", what I want is starting the cursor on the "EditText" I choose for example first "EditText".

Note: I'm using Activity contains Scrollview and Constraint layout.

Ahmed Said
  • 71
  • 2
  • 10

2 Answers2

1

Put <requestFocus> in the XML of the EditText you want to have initial focus. See Layout Resources.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • Thanks a lot, I really appreciate it. – Ahmed Said Oct 01 '17 at 02:12
  • 1
    @AhmedSaid No problem. You may also want to familiarize yourself with the XML tag `nextFocusForward` to make sure you proceed through your layout in the order you want. Android does a pretty good job at guessing the right order, but sometime it's a little off. – Cheticamp Oct 01 '17 at 02:21
  • Yest you are right too,Android documentation is pretty clear. Thanks :))) – Ahmed Said Oct 01 '17 at 02:43
1

Programmatically:

edittext.requestFocus();

Through XML:

<EditText...>
    <requestFocus />
</EditText>

Or call onClick method manually.