android笔记 自动补全输入的MultiAutoCompleteTextView

AutoCompleteTextView类似的自动补全输入组件,但可以设置分词起,根据分词条件为新输入的子段提供自动补全。

package tjj.autocomplete;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;

public class Test_autocompliteActivity extends Activity {
    /** Called when the activity is first created. */	
	private static final String[] autoStr= {"a", "ab","abc", "ad"};
	private MultiAutoCompleteTextView multi;	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.myspinner, autoStr);
        
        /*MultiAutoCompleteTextView会对输入文本的部分进行匹配,AutoCompleteTextView是把你所有的字符串当做子串去做匹配,
         *而MultiAutoCompleteTextView会根据你提供tokenizer来分解你已经输入的字符串,并对符合条件的最后几个字符当做子串去做自动提示,
         *新输入的部分要用逗号隔开,你需要注意的是提供分词方式*/
        multi = (MultiAutoCompleteTextView)findViewById(R.id.myAutoComplete);
        
        multi.setAdapter(adapter);
        /*设置为逗号分词器,后面那个单词,comma为逗号,tokenizer为分词器*/
        multi.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    }
}


你可能感兴趣的:(android,String,Class)