Android:EditText maxLength被忽略 [英] Android: EditText maxLength being ignored

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

问题描述

我有一个问题,这个EditText完全忽略了我的maxLength.

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,因为当我按OK时,它以编程方式可用.

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..
                }
            } );
     .....

我解决了. 问题是这一行:

        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.

这似乎是两个问题

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


我看到您已经解决了!好的,问题是...


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!

这篇关于Android:EditText maxLength被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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