Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace the comma with a space when I use the "MultiAutoCompleteTextView"

I'm doing a simple program using MultiAutoCompleteTextView to prompt the common words when I input several letters.

code:

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
            this,
            android.R.layout.simple_dropdown_item_1line, 
            ary);
    MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.editText);
    textView.setAdapter(adapter);

    textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    private String[] ary = new String[] {
       "abc",
       "abcd",
       "abcde",
       "abcdef",
       "abcdefg",
       "hij",
       "hijk",
       "hijkl",
       "hijklm",
       "hijklmn",
    };

Now,when I input 'a' and choose "abcd" but the result become to "abcd,". How to replace the comma with a space?

Thank you!

like image 920
huaigu Avatar asked Aug 14 '10 10:08

huaigu


2 Answers

Check my question/answer

How to replace MultiAutoCompleteTextView drop down list

you will find a SpaceTokenizer class

like image 195
vsm Avatar answered Nov 18 '22 14:11

vsm


The way to do it would be to implement your own Tokenizer. The reason the comma comes up is because you're using CommaTokenizer, which is designed to do exactly that. You can also look at the source code for CommaTokenizer if you need a reference for how to implement your own SpaceTokenizer.

like image 2
Dan Lew Avatar answered Nov 18 '22 14:11

Dan Lew