Gaurav
Gaurav

Reputation: 667

Removing autofocus from EditText and regaining focus ?

I have an EditText and a set of Buttons in my layout. To remove autofocus from EditText i am using a dummy LinearLayout as told in some answers at this site.

I want the edit text to get focus on button press and the virtual keyboard being shown. but on 1st button press the edit text gets focus but virtual keyboard is shown only after button is pressed again.well the problem is bit different but any idea? This is what i m doing on button click:

b.setOnClickListener(new OnClickListener() {
    @Override
     public void onClick(View v) {
        // TODO Auto-generated method stub
         mgr.showSoftInput(main_edt,InputMethodManager.SHOW_FORCED);
     main_edt.requestFocus();
        } 
});

This is the dummy linear layout:

<LinearLayout 
    android:focusable="true" 
    android:id="@+id/dummyll"
    android:focusableInTouchMode="true" 
    android:layout_width="0px"
    android:layout_height="0px" />  

If i dont write this dummy linear layout or make the focusable tags as false the keyboard shows on 1st click only.

Upvotes: 1

Views: 3839

Answers (2)

Tomas Vondracek
Tomas Vondracek

Reputation: 143

Add attribute android:windowSoftInputMode="stateHidden" to the activity in your manifest. This way, the soft keyboard will no be shown, when you start the activity.

Upvotes: 0

Senthil Mg
Senthil Mg

Reputation: 3313

Let's try to set the below properties in your xml itself for EditText

android:focusableInTouchMode="true" android:cursorVisible="false".

I hope it may solve your problem,if you suppose want to hide the softkeypad itself at launching activity means use the below code in your activity getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Upvotes: 3

Related Questions