带正则表达式的 Android AutoCompleteTextView? [英] Android AutoCompleteTextView with Regular Expression?

查看:44
本文介绍了带正则表达式的 Android AutoCompleteTextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是 Android 新手,之前是 iOS、.Net,之前是 C 和 Fortran.

noob to Android here, coming from iOS, .Net before that, C and Fortran way before all that.

如果我有一个包含 1000 多个字符串的 ArrayAdapter,我如何修改 AutoCompleteTextView(或 MultiAutoCompleteTextView 或任何派生类),以便我可以使用正则表达式修改字符串的匹配条件.

If I have an ArrayAdapter with some 1000+ string on it, how could I modify an AutoCompleteTextView (or MultiAutoCompleteTextView or any derived Class) so that I can modify the match criteria of the strings with a regular expression.

用一个简短的例子更容易理解:

It's easier to understand with a short example:

ArrayAdapter 的典型内容:

Typical content of ArrayAdapter:

W 20 x 100
W 16 x 89    -> 1
W 16 x 15    -> 2
WT 8 x 44
C 9

我想忽略用户是否使用空格 OR/AND 小写 'x' 来呈现可能匹配的列表'

I want to ignore whether the or not the user uses spaces OR / AND lowercase 'x' to present a list of possible matches'

所以如果用户输入 W 16xW16 xw16 ->1->2 将显示在自动完成建议列表中.

So if the user types W 16x or W16 x or w16 both ->1 and ->2 will show up on the autocomplete suggestion list.

推荐答案

既然你是一名编码员,我会让你走上正确的道路......这不是写在你的例子中,而是一个通用的例子Java/Android 中的正则表达式.

Since you're a coder I'll get you on the right path ... this isn't written to your example, but rather a general example of RegEx in Java/Android.

protected ArrayList<String> splitMsg(SmsMessage smsMessage) {
        ArrayList<String> smt;
        Pattern p = Pattern.compile(".{1,160}");
        Matcher regexMatcher = p.matcher(smsMessage.getMsgBody());
        smt = new ArrayList<String>();
        while (regexMatcher.find()) {
            smt.add(regexMatcher.group());
        }
        return smt;
    }

没有验证,因此您必须实施:

There's no validation so you'll have to implement:

smsMsgBody_editText.addTextChangedListener(new TextWatcher() {
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        /*
         * Do something fancy like regex match ;)
        */
    }
});

这篇关于带正则表达式的 Android AutoCompleteTextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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