Search code examples
javaandroidpositioncursor

How do I position the cursor at a default position?


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


Solution

  • 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();