Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. String asd[]={"A","B","C","AAA","BBB","CCC"};
  2.  
  3. private static final String[] COUNTRIES = new String[] {"Belgium", "France", "Italy", "Germany", "Spain"};
  4.  
  5.  
  6. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
  7. MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.edit);
  8. textView.setAdapter(adapter);
  9. textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
  10.  
  11. public static class SemicolonTokenizer implements Tokenizer {
  12. public int findTokenStart(CharSequence text, int cursor) {
  13. int i = cursor;
  14. while (i > 0 && text.charAt(i - 1) != ';') {
  15. i--;
  16. }
  17. while (i < cursor && text.charAt(i) == ' ') {
  18. i++;
  19. }
  20. return i;
  21. }
  22. public int findTokenEnd(CharSequence text, int cursor) {
  23. int i = cursor;
  24. int len = text.length();
  25. while (i < len) {
  26. if (text.charAt(i) == ';') {
  27. return i;
  28. } else {
  29. i++;
  30. }
  31. }
  32. return len;
  33. }
  34. public CharSequence terminateToken(CharSequence text) {
  35. int i = text.length();
  36. while (i > 0 && text.charAt(i - 1) == ' ') {
  37. i--;
  38. }
  39. if (i > 0 && text.charAt(i - 1) == ';') {
  40. return text;
  41. } else {
  42. if (text instanceof Spanned) {
  43. SpannableString sp = new SpannableString(text + "; ");
  44. TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
  45. Object.class, sp, 0);
  46. return sp;
  47. } else {
  48. return text + "; ";
  49. }
  50. }
  51.  
  52. textView.setTokenizer(new SemicolonTokenizer());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement