Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: get rid of focus when enter activity [duplicate]

Tags:

android

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?

like image 310
Bin Chen Avatar asked Oct 10 '11 10:10

Bin Chen


2 Answers

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"/>
like image 88
Paresh Mayani Avatar answered Sep 23 '22 13:09

Paresh Mayani


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

android:windowSoftInputMode="stateHidden"
like image 41
anujprashar Avatar answered Sep 21 '22 13:09

anujprashar