9

Possible Duplicate:
Stop EditText from gaining focus at Activity startup?

I have an activity has a EditText inside, and each time when the activity starts up, the EditText automatically get the focus.

I don't want the EditText gets the focus automatically, how can I do?

Community
  • 1
  • 1
Bin Chen
  • 61,507
  • 53
  • 142
  • 183

3 Answers3

16

I had the similar issue and i am sure this is the problem, for that you just need to do a small trick.

Add this LinearLayout before the EditText which is getting focus at activity startup. You don't need to set any value inside the EditText.

<LinearLayout
    android:focusable="true" 
    android:focusableInTouchMode="true"
    android:layout_width="0dip" 
    android:layout_height="0dip"
    android:id="@+id/dummyView"/>
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • not very clear, can you repeat more precisely? Thanks! Should I set anything to the EditText? – Bin Chen Oct 10 '11 at 10:54
  • 1
    just above the EditText, add this LinearLayout, and you don't need to do any changes for EditText, FYI, we have added this layout as a dummy so that it will get focus while starting of activity. – Paresh Mayani Oct 10 '11 at 11:00
2

Add this in <activity> tag in your manifest for activity in which edittext is present.

android:windowSoftInputMode="stateHidden"
anujprashar
  • 6,263
  • 7
  • 52
  • 86
0

put android:focusable="false" may it will work for edittext

Luke
  • 11,426
  • 43
  • 60
  • 69
mathlearner
  • 7,509
  • 31
  • 126
  • 189