MultiAutoCompleteTextView的使用

在xml中添加MultiAutoCompleteTextView,代码部分添加字符串为MultiAutoCompleteTextView提供数据源,设置适配器,添加

setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer())设置分隔符并作为单个输入结束符号
public class MainActivity extends AppCompatActivity {
    private MultiAutoCompleteTextView multiAutoCompleteTextView;
    private String[]res={"jiangxi","jiangxishen","jiangxishentushuguan","jiangxidianshitai","jiangxishifandaxue"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,res);
        multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView);
        multiAutoCompleteTextView.setAdapter(arrayAdapter);
        multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    }
}

MultiAutoCompleteTextView的使用_第1张图片

你可能感兴趣的:(Android,相关)