开发者

stop user from inputting in to the edit box?

i want the EidtText to stop accepting input from the user if the input text length is more than 10 ..but it should be able to delete the already available text in the EditText even though the text length is more than 10 ...

can some one help me w开发者_高级运维ith the code pls..

thanks :)


Have you tried limiting the number of character of the EditText ? If not take a look at this

EditText et = new EditText(this);

int maxLength = 3;

InputFilter[] FilterArray = new InputFilter[1];

FilterArray[0] = new InputFilter.LengthFilter(maxLength);

et.setFilters(FilterArray);


Use EditText's setKeyListener method to set a custom KeyListener that limits the length of the text in the control


For reference:

In cases where I want to track more than one type of max limit (multiple field shared max limit, individual field max limit), I look at the selection position in the edit.

If the position is larger than my smallest max value, I just take the left max characters. If the position is smaller than my max value, I take the left position characters, subtract that from the max, then take the remaining right characters.

You only need to do this if you will have more than one possible limiter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜