当前位置: 移动技术网 > 移动技术>移动开发>Android > android开发控件之AutoCompleteTextViewt

android开发控件之AutoCompleteTextViewt

2018年03月18日  | 移动技术网移动技术  | 我要评论
5、AutoCompleteTextViewt是自动补全提示这里是单个提示,这种搜索提示到处可见,最简单的就是搜索引擎的搜索提示
//在xml中

    
>在activity里的代码
  //这部分是做一个搜索框单个
            /*
            第一步:初始化控件
            第二步:初始化适配器
            第三步:找到一个数据源
            第四步:将 adapter与当前AutoCompleteTextView匹配
            * */
        acCompleteText = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, res);
        acCompleteText.setAdapter(adapter);

    //MultiAutoCompleteTextView,可以多个提示,这部分是做发送邮件可以多选的搜索框
            /*
            第一步:初始化控件
            第二步:初始化适配器
            第三步:找到一个数据源
            第四 :将 adapter与当前AutoCompleteTextView匹配
            第五步:设置以逗号作为分隔符
            * */
        macCompleteText =   (MultiAutoCompleteTextView) findViewById(R.id.MautoCompleteTextView);
        ArrayAdapter madapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, res);
        macCompleteText.setAdapter(madapter);
        macCompleteText.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
       //其中res是提前声明的一个数组
       private String[] res = {"beingjing", "beijign1", "beijing2", "zhang", "zhanyyan"};
      // 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网