Home > DeveloperSection > Forums > Stop EditText from gaining focus at Activity startup
Samuel Fernandes
Samuel Fernandes

Total Post:159

Posted on    April-23-2015 5:08 AM

 Android Android  Android Edittext 

 1 Reply(s)
 896  View(s)
Rate this:
I have an Android Activity, with two elements:


When my Activity starts, the EditText immediately has input focus (flashing cursor). I don't want any control to have input focus at startup. I tried:


No luck. How can I convince the EditText to not select itself when the Activity starts?

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    April-23-2015 7:53 AM

<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
    android:focusable="true" android:focusableInTouchMode="true"
    android:layout_width="0px" android:layout_height="0px"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
     to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:nextFocusUp="@id/autotext" android:nextFocusLeft="@id/autotext"/>

Don't want to miss updates? Please click the below button!

Follow MindStick