如何prevent虚拟键盘时显示的窗口小部件的EditText长期preSS? [英] How to prevent virtual keyboard displaying when long-press on EditText Widget?

查看:158
本文介绍了如何prevent虚拟键盘时显示的窗口小部件的EditText长期preSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EditText小部件在我的应用程序,我已经设置为只读,我想知道,当用户长期presses就可以了。我不希望当用户点击这个插件的虚拟键盘弹出。

要出现,我用这个停止虚拟键盘:

文字的​​EditText =(EditText上)findViewById(R.id.editText01); editText.setClickable(假);

这工作,但我不能让任何长期preSS的消息,如果我使用OnLongClickListener()。

有谁知道我可以prevent弹出式键盘的出现,但仍获得长期preSS事件?

感谢。

编辑:我真的试图提供给这个问题的前两个答案,但是都没有成功。最后我做的事,是对部件的EditText我用下面的:

  editText.setInputType(InputType.TYPE_NULL);
editText.setCursorVisible(假);
editText.setOnLongClickListener(mOnLongClickListener);
 

在setInputType()方法调用关闭点击的小部件。该setOnLongClickListener()函数将处理在小部件的所有长preSS事件,我回一个真正的从常规基本上消耗了长期preSS事件。所以,我现在有一个EditText小部件,不会有虚拟键盘弹出时pressed,但在该部件一个长期preSS会打电话给我的监听器方法。

解决方案

  button.setOnLongClickListener(View.OnLongClickListener L(){

//覆盖的方法

//那么做

InputMethodManager IMM =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(),0);
});
 

I've got an EditText widget in my app which I have set to read-only, and I want to know when the user long-presses on it. I don't want the virtual keyboard to popup if the user taps on this widget.

To stop the virtual keyboard from appearing, I'm using this:

EditText text = (EditText)findViewById(R.id.editText01); editText.setClickable(false);

This works, but I can't get any long-press messages if I use OnLongClickListener().

Does anyone know how I can prevent the popup keyboard to appear, but still get long-press events?

Thanks.

EDITED: I actually tried the first two answers supplied to this question, and neither worked. What I ended up doing, was for the EditText widget I used the following:

editText.setInputType(InputType.TYPE_NULL);
editText.setCursorVisible(false);
editText.setOnLongClickListener(mOnLongClickListener);

The setInputType() method call turns off clicks to the widget. The setOnLongClickListener() routine will handle all long-press events on the widget, and I return a true from that routine which basically consumes the long-press event. So, I now have an EditText widget that won't have the virtual keyboard popup when pressed, but a long-press on that widget will call my listener method.

解决方案

button.setOnLongClickListener (View.OnLongClickListener l(){

//override the method  

//then do this

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
});

这篇关于如何prevent虚拟键盘时显示的窗口小部件的EditText长期preSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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