Multiple EditText - specify cursor location

In my class, I create two EditTexts.

editText1 = (EditText)findViewById(R.id.EditText1);
editText2 = (EditText)findViewById(R.id.EditText2);

When I launch the application, the cursor is automatically placed in the second EditText. How can I change to be set in the first EditText? Do I have to change something programmatically or in XML?

+5
source share
3 answers

you can try:

editText1.requestFocus();
+4
source

There are two ways to do this in your class, for example

   editText1.requestFocus();

and the other in xml for example

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <requestFocus />
</EditText>
+3
source

This is determined by those who request focus. Get the object you want to focus and request focus, and it will light up and the cursor should appear there.

+1
source

All Articles