开发者

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 virtua开发者_JS百科l 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.


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜