EditText上没有采取数字输入 [英] EditText is not taking numeric input

查看:96
本文介绍了EditText上没有采取数字输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序一个EditText视图。我的EditText没有采取整数值作为输入但它正在采取所有其他的人。以下是我的EditText查看。

 <的EditText
机器人:ID =@ + ID / txtSearchItems
机器人:layout_width =75dp
机器人:layout_height =WRAP_CONTENT
机器人:知名度=看得见
机器人:提示=搜索
机器人:TEXTSIZE =14dp
机器人:layout_alignParentLeft =真
机器人:layout_marginTop =2DP
机器人:layout_centerHorizo​​ntal =真正的>
< /&的EditText GT;


我遇到一次,犯罪嫌疑人

解决方案

在可能的问题是:该EditText上可能被包含在一个XML布局文件和布局文件将被用于一个对话实例。当对话实例的onKeyListener将返回不相关的键一些无效的默认值即回归真正的出现问题。在这种情况下,您的EditText会举止异常。样品code的情况是

 对话D =新的对话框(背景);
    d.setContentView(R.layout.mylayout);
    d.setOnKeyListener(新OnKeyListener(){                    @覆盖
                    公共布尔安其(DialogInterface对话,诠释关键code,
                            KeyEvent的事件){
                        Log.i(安其,重点code +==安其);
                        如果(键code == KeyEvent.KEY code_BACK){
                                返回true;
                        }
                        返回true; //!这是错误的,应该返回false;
                    }
                });
            }

I have an EditText view in my android application. My EditText is not taking integer values as an input however it is taking all the other ones. the following is my EditText View.

<EditText
android:id="@+id/txtSearchItems"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:hint="Search"
android:textSize="14dp"
android:layout_alignParentLeft="true" 
android:layout_marginTop="2dp"
android:layout_centerHorizontal="true">
</EditText>

解决方案

On the possible issue that i faced once and suspects is: The EditText might be contained in an XML layout file and the layout file will be used for a Dialog instance. The problem occurs when the onKeyListener of the Dialog instance is returning some invalid default value i.e. 'return true' for irrelevant keys. In such case your EditText will be behaving strangely. The sample code for the scenario is

Dialog d=new Dialog(context);
    d.setContentView(R.layout.mylayout);
    d.setOnKeyListener(new OnKeyListener() {

                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode,
                            KeyEvent event) {
                        Log.i("onkey", keyCode + " == Onkey");
                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                                return true;
                        }
                        return true;  // !!! this is wrong it should be return false;
                    }
                });
            }

这篇关于EditText上没有采取数字输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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