2

The image shows the screenshot of my application. As you can see that the cursor is at the text field pertaining to "Height". Whenever I launch my app the default cursor position is at "Height". I want it to be on "Mass". How do I do it ? I can't figure out. Please help.!

Screenshot

Blue Ice
  • 7,888
  • 6
  • 32
  • 52
CodeWalker
  • 2,281
  • 4
  • 23
  • 50
  • Try putting this in your onCreate: massEditText.requestFocus(); (You'll need to change the edittext name to whatever yours is called) – Noob Mar 13 '14 at 16:04
  • possible duplicate of [EditText request focus](http://stackoverflow.com/questions/8077755/edittext-request-focus) – Max Meijer Mar 13 '14 at 16:07

2 Answers2

1

Take a look at your .xml file:

   <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:ems="10" >

        <requestFocus />

    </EditText>

And set the <requestFocus /> tag appropriately. Also, you can call:

EditText.requestFocus();
Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
0

Either update your .xml file as follows.

<EditText 
 android:id=@+id/etMass
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
    <requestFocus/> </EditText>

Or Use Code:

EditText etMass = (EditText) findViewById(R.id.etMass);
etMass.requestFocus();
Sunil Shrestha
  • 303
  • 1
  • 7