gpt4 book ai didi

android - 在 Android 的输入过滤器中使用条件 maxLength

转载 作者:行者123 更新时间:2023-11-29 22:13:26 24 4
gpt4 key购买 nike

我正在使用输入过滤器:

int max_length;
max_length = 15;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(max_length);

final EditText input = new EditText(getBaseContext());
input.setFilters(FilterArray);
alert_screen.setView(input);

有效,但我需要将 max_length 设为条件值。例如,如果用户只输入数字,则 max_length 将等于 15,但如果用户输入一些字母,则 max_length 必须等于 11。

最佳答案

你应该首先使用 TextWatcher ,因为你的编辑文本中的文本发生了变化....

http://developer.android.com/reference/android/text/TextWatcher.html

如果用户在 edittext 中输入任何字母,则 max 的条件发生变化,如果只有数字也发生变化,则将此条件放入 onTextChanged(CharSequence s, int start, int before, int count)

Just refrences is::

http://thiranjith.wordpress.com/2010/12/12/how-to-specify-maximum-length-for-edittext-in-android/

关于android - 在 Android 的输入过滤器中使用条件 maxLength,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9045750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com