3

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

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:

Typical content of ArrayAdapter:

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

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

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

4

1 回答 1

2

由于您是一名编码员,我会让您走上正确的道路……这不是写给您的示例,而是 Java/Android 中 RegEx 的一般示例。

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;
    }

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

smsMsgBody_editText.addTextChangedListener(new TextWatcher() {
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        /*
         * Do something fancy like regex match ;)
        */
    }
});
于 2011-04-17T09:35:21.327 回答