安卓的EditText最大长度被忽略(解决) [英] Android: EditText maxLength being ignored (Solved)

查看:180
本文介绍了安卓的EditText最大长度被忽略(解决)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我哪里有这个EditText上完全忽略我的最大长度的问题。

I have a problem where this EditText ignores my maxLength completely.

<EditText
        android:id="@+id/dialog_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:inputType="numberPassword"
        android:maxLength="4"
        android:singleLine="true"
        android:textColorHint="@color/primary_lighter"
        android:textColor="@color/accent_harder"
        android:hint="****"
        />

我可以输入我有多少个字符想要的。

I can input how many characters I want.

这是一个对话框,我不能findViewById因为它可拿到的EditText programtaically当我preSS确定。

This is a dialog and I cannot get the EditText by findViewById because its available programtaically when I press OK.

public void showNewQuestionDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder( this );
    LayoutInflater inflater = this.getLayoutInflater();
    builder.setView( inflater.inflate( R.layout.dialog_question_new, null ) )
            .setPositiveButton( R.string.settings_ok, new  DialogInterface.OnClickListener() {
                @Override
                public void onClick( DialogInterface thisDialog, int id ) {
                    Dialog dialog2 = Dialog.class.cast( thisDialog );
                    EditText input = ( EditText ) dialog2.findViewById( R.id.dialog_input ); 

                    // Other code here..
                }
            } );
     .....

我解决它。
问题是这一行:

I solved it. The problem was this line:

        android:singleLine="true"

如果你曾经遇到同样的问题,尝试删除此行。

If you ever experience the same problem, try removing this line.

推荐答案

我想确保你的XML属性不会影响另一个。

I would make sure that your XML attributes are not effecting another one.

这似乎是这两个可能是这个问题。

It seems like these 2 could be the issue

    android:maxLength="4"
    android:singleLine="true"


我看你解决它了! OK,这个问题是...


I see you solved it already! OK, the issue was...

    android:singleLine="true"

但是,你应该仔细检查,以确保您不能创建一个新行!

But you should double check to make sure that you cannot create a new line!

这篇关于安卓的EditText最大长度被忽略(解决)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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