安卓:在EditText上显示键盘 [英] Android : show keyboard in edittext

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

问题描述

我坚持与在Android应用程序中的pretty的简单的问题我的编码。我的EditText对象,一个每行中的列表。

Am stuck with a pretty simple issue in the Android App am coding. I have a list of EditText objects, one in each row.

当用户长presses的EditText上,我需要显示的键盘。当用户执行长preSS,然后调用这个方法:

When the user long presses the EditText, I need to show the keyboard. When the user does a long press, then I call this method :

private void setNameAsEditable (View rowView, boolean setToEditable) {

    EditText textView = (EditText) rowView
            .findViewById(R.id.edittext_name);
    textView.setFocusableInTouchMode(setToEditable);
    textView.setFocusable(setToEditable);
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
   }

在EditText上变为可编辑(下划线光标出现时,你可以看到如下图)

The edittext becomes editable (the underline and the cursor appears, as you can see below)

但键盘不上来。

我尝试了各种解决方案,从计算器(像这样的 EditText上没有显示虚拟键盘),但不成功。

I tried various solutions from stackoverflow (like this one EditText is not showing virtual keyboard), but in vain.

我甚至尝试

  this.getWindow().setSoftInputMode ( WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

我要的软键盘,只要用户长期presses的EditText上冒出来。是否有人可以帮忙吗?

I want the soft-keyboard to come up as soon as the user long-presses the EditText. Can someone please help?

推荐答案

这是什么工作终于(Amit的答案+ Tamilan的答案):非常感谢!

This is what worked finally ( Amit's answer + Tamilan's answer) Thanks so much!

private void setNameAsEditable (View rowView, boolean setToEditable) {

    EditText textView = (EditText) rowView
            .findViewById(R.id.edittext_name);
    textView.setFocusableInTouchMode(setToEditable);
    textView.setFocusable(setToEditable);

    InputMethodManager imm = (InputMethodManager) getContext().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(textView.getWindowToken(), 0);

    if (setToEditable) {
         textView.requestFocus();
        imm.showSoftInput(textView, 0);
    }
}

这篇关于安卓:在EditText上显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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