机器人的EditText最大长度不工作 [英] android EditText maxLength not working

查看:248
本文介绍了机器人的EditText最大长度不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的XML

 <的EditText
机器人:ID =@ + ID / et_comment
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
安卓的inputType =textNoSuggestions | textVisiblePassword
机器人:提示=请在这里提供意见......
机器人:重力=顶
机器人:最大长度=5
机器人:TEXTSIZE =12SP
机器人:知名度=看得见
/>

也不是在工作使用此code

  TextView的editEntryView =新的TextView(...);
输入过滤器[] = filterArray新输入过滤器[1];
filterArray [0] =新InputFilter.LengthFilter(5);
editEntryView.setFilters(filterArray);

maxLenth不工作,我不知道为什么,但它不是。结果
我已经检查了堆栈上其他的答案,但他们也没有工作。结果
请检查是否有任何的EditText属性是相互冲突的,或有什么问题?

编辑:同样的问题所面临的其他开发人员结果
看评论这里同样的问题正面临曼西和AAT结果
这里在同样的问题所面临的泳儿和提升<意见/ p>

编辑:问题解决了结果
我使用的输入滤波器,覆盖XML使得它不能正常工作的最大长度。结果
究其原因输入滤波器没有工作对我来说是我用另一种输入滤波器,覆盖previous最大长度输入滤波器。结果
使它成为一个单一的输入滤波器固定我的问题。


解决方案

相当老的文章,但我注意到了XML是如何实际的EditText 对象,而要添加过滤器到的TextView 它可以处理它不同于的EditText 。如果手动添加输入过滤对象,xml属性将被覆盖。

这个例子code在其上添加输入过滤 S到查看似乎是一个的TextView 对象。请确保你拉右视图,它被转换为的EditText 如果用手动添加的过滤器去 - 这是为我工作,现在

祝你好运。

This is my xml

<EditText
android:id="@+id/et_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|textVisiblePassword"
android:hint="Provide comments here..."
android:gravity="top"
android:maxLength="5"
android:textSize="12sp"
android:visibility="visible"
/>

Neither is it working using this code

TextView editEntryView = new TextView(...);
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(5);
editEntryView.setFilters(filterArray);

maxLenth is not working, I dont know why, but it isnt.
I have checked other answers on the stack but they are also not working.
Please check if any of EditText attributes are conflicting or what is the problem?

EDIT: Same problem is being faced by other developers
See comments here same problem is being faced by Mansi and aat
And here in comments same problem is being faced by Vincy and Riser

EDIT: Problem solved
I was using input filter which overrides the max length in xml making it not able to work.
The reason input filter didn't worked for me was that I was using another input filter which overwrites the previous maxLength input filter.
Making it into a single input filter fixed that issue for me.

解决方案

Fairly old post but, I noticed how the XML is an actual EditText object, while you are adding the filters to a TextView which could handle it differently than EditText. If you are adding an InputFilter object manually, the xml property is overridden.

The example code on which you add InputFilters to the View seems to be a TextView object. Make sure you pull the right view and it's being cast to EditText if you go with the manual addition of the filters--it's working for me right now.

Good luck.

这篇关于机器人的EditText最大长度不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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