I have figured out how to do the custom tokenizer by looking at the
sources for android, although for some reason it allows for matching
of strings when the buffer is empty, even without the @ sign, anybody
got any ideas?
Here's what I came up with:
package com.example.util;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.widget.MultiAutoCompleteTextView.Tokenizer;
/**
* AtTokenizer allows for auto-completion of user names starting with
an @ sign.
*
* @author torgny.bjers
*/
public class AtTokenizer implements Tokenizer {
/**
* @see
android.widget.MultiAutoCompleteTextView.Tokenizer#findTokenStart
(java.lang.CharSequence,
* int)
*/
public int findTokenStart(CharSequence text, int cursor) {
int i = cursor;
while (i > 0 && text.charAt(i - 1) != '@')
i--;
while (i < cursor && text.charAt(i) == ' ')
i++;
return i;
}
/**
* @see
android.widget.MultiAutoCompleteTextView.Tokenizer#findTokenEnd
(java.lang.CharSequence,
* int)
*/
public int findTokenEnd(CharSequence text, int cursor) {
int i = cursor;
int len = text.length();
while (i < len) {
if (text.charAt(i) == '@') {
return i;
} else {
i++;
}
}
return len;
}
/**
* @see
android.widget.MultiAutoCompleteTextView.Tokenizer#terminateToken
(java.lang.CharSequence)
*/
public CharSequence terminateToken(CharSequence text) {
int i = text.length();
while (i > 0 && text.charAt(i - 1) == ' ')
i--;
if (i > 0 && text.charAt(i - 1) == '@') {
return text;
} else {
if (text instanceof Spanned) {
SpannableString sp = new SpannableString(text);
TextUtils.copySpansFrom((Spanned) text, 0,
text.length(),
Object.class, sp, 0);
return sp;
} else {
return text;
}
}
}
}
On Dec 20 2008, 12:42 pm, Torgny <[email protected]> wrote:
> Hello,
>
> I have looked everywhere for any kind of hint of how to implement a
> custom Tokenizer using the MultiAutoCompleteTextView.Tokenizer
> interface, but have come up empty. As a last resort I was hoping that
> someone here could provide me with a basic example of how to implement
> the Tokenizer class so that I can hook it into the TextView with the
> setTokenizer() method.
>
> These are the examples and reference docs I was looking at:
>
> http://code.google.com/android/reference/android/widget/MultiAutoComp...http://code.google.com/android/samples/ApiDemos/src/com/example/andro...
>
> I know this is probably a very trivial issue. I am new to both Java
> and Android and would appreciate any help you can give me. Thank you!
>
> Warm Regards,
> Torgny
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---