問(wèn)題描述
這是我的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"
/>
使用此代碼也不行
TextView editEntryView = new TextView(...);
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(5);
editEntryView.setFilters(filterArray);
maxLenth 不工作,我不知道為什么,但它不工作.
我已經(jīng)檢查了堆棧上的其他答案,但它們也不起作用.
請(qǐng)檢查是否有任何 EditText 屬性沖突或有什么問(wèn)題?
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?
其他開(kāi)發(fā)人員也面臨同樣的問(wèn)題
查看評(píng)論這里 Mansi 和 aat 面臨同樣的問(wèn)題
而 這里 在評(píng)論中,Vincy 和 Riser 也面臨同樣的問(wèn)題
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
問(wèn)題已解決
我正在使用輸入過(guò)濾器,它覆蓋了 xml 中的最大長(zhǎng)度,使其無(wú)法工作.
輸入過(guò)濾器對(duì)我不起作用的原因是我使用了另一個(gè)輸入過(guò)濾器,它覆蓋了以前的 maxLength 輸入過(guò)濾器.
把它變成一個(gè)單一的輸入過(guò)濾器為我解決了這個(gè)問(wèn)題.
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.
推薦答案
相當(dāng)老的帖子但是,我注意到 XML 是一個(gè)實(shí)際的 EditText
對(duì)象,而您正在將過(guò)濾器添加到 TextView
處理它的方式與 EditText
不同.如果您要手動(dòng)添加 InputFilter
對(duì)象,則會(huì)覆蓋 xml 屬性.
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.
您將 InputFilter
s 添加到 View
的示例代碼似乎是一個(gè) TextView
對(duì)象.如果您手動(dòng)添加過(guò)濾器,請(qǐng)確保您拉出正確的視圖并將其轉(zhuǎn)換為 EditText
- 它現(xiàn)在對(duì)我有用.
The example code on which you add InputFilter
s 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.
祝你好運(yùn).
這篇關(guān)于android EditText maxLength 不起作用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!