Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple EditText - specify the cursor's location

In my class I create two EditTexts.

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

When I start the app, the cursor is automatically put in the second EditText. How can I change to be set in the first EditText? Should I change something programmatically or in the XML?

like image 456
MMMM Avatar asked Feb 02 '12 12:02

MMMM


2 Answers

you can try:

editText1.requestFocus();
like image 64
Natali Avatar answered Oct 15 '22 14:10

Natali


there is two way of doing this one in your class like

   editText1.requestFocus();

and another in xml like

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

    <requestFocus />
</EditText>
like image 45
Akram Avatar answered Oct 15 '22 13:10

Akram