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.!
Asked
Active
Viewed 155 times
2
-
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
-
Thanks! It's working. – CodeWalker Mar 13 '14 at 16:12
2 Answers
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
- 49,738
- 23
- 176
- 183
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
- 278
- 1
- 6