在AlertDialog Softkeyboard不显示 [英] Softkeyboard not showing in a AlertDialog

查看:151
本文介绍了在AlertDialog Softkeyboard不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个节目 AlertDialog 的EditText 在里面,问题是,一个菜单项,虽然它重点是在softkeyboard没有按节目,直到我点击的EditText,任何人有一个解决方案吗?我试过

  InputMethodManager IMM =(InputMethodManager)
                         getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText,InputMethodManager.SHOW_IMPLICIT);

但它不工作。这里是我的code

  @覆盖
公共布尔onOptionsItemSelected(菜单项项){
    回报(applyMenuChoice(项目)|| super.onOptionsItemSelected(项目));
}私人布尔applyMenuChoice(菜单项项){
    开关(item.getItemId()){
    案例搜索:
        最后AlertDialog.Builder警报=新AlertDialog.Builder(本);
        最终的EditText输入=新的EditText(本);
        input.setMinimumWidth(300);
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        alert.setView(输入);
        alert.setPositiveButton(OK,
                新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话框,
                            INT whichButton){
                        字符串值= input.getText()的toString()修剪()。
                        Toast.makeText(getApplicationContext(),价值,
                                Toast.LENGTH_SHORT).show();
                    }
                });        alert.show();
        返回(真);
    案例DELETE:
        getListView()setAdapter(空)。
        返回(真);
    }
    返回(假);
}


解决方案

试试这个code,

打开

  ettext.requestFocus();
                ettext.postDelayed(新的Runnable(){
                    @覆盖
                    公共无效的run(){
                        InputMethodManager键盘=(InputMethodManager)
                        getSystemService(Context.INPUT_METHOD_SERVICE);
                        keyboard.showSoftInput(ettext,0);
                    }
                },200);

So i have a menu item that shows AlertDialog with a EditText in it, the problem is that although it is focused the softkeyboard doesn show until I click on the edittext, anyone got a solution ? I tried

InputMethodManager imm = (InputMethodManager)
                         getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

but it doesn work. Here is my code

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    return (applyMenuChoice(item) || super.onOptionsItemSelected(item));
}

private boolean applyMenuChoice(MenuItem item) {
    switch (item.getItemId()) {
    case SEARCH:
        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
        final EditText input = new EditText(this);
        input.setMinimumWidth(300);
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        alert.setView(input);
        alert.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int whichButton) {
                        String value = input.getText().toString().trim();
                        Toast.makeText(getApplicationContext(), value,
                                Toast.LENGTH_SHORT).show();
                    }
                });

        alert.show();       
        return (true);
    case DELETE:
        getListView().setAdapter(null);
        return (true);
    }
    return (false);
}

解决方案

Try this code,

TO OPEN

                 ettext.requestFocus();
                ettext.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        InputMethodManager keyboard = (InputMethodManager)
                        getSystemService(Context.INPUT_METHOD_SERVICE);
                        keyboard.showSoftInput(ettext, 0);
                    }
                },200);

这篇关于在AlertDialog Softkeyboard不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆