美文网首页
Android自动匹配输入控件AutoCompleteTextV

Android自动匹配输入控件AutoCompleteTextV

作者: 百里漫步 | 来源:发表于2017-10-14 10:21 被阅读0次

    自动匹配输入控件AutoCompleteTextView和Multi AutoCompleteTextView
    属性 android:completionThreshold="3"指输入到第几个字符开始匹配
    下面给出实例:

            <AutoCompleteTextView 
                android:id="@+id/AutoCompleteTextView_name"
                android:completionThreshold="3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/content" />
            <MultiAutoCompleteTextView 
                android:id="@+id/AutoCompleteTextView_name2"
                android:completionThreshold="3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/content" />
    

    然后是Java文件:

            //1、首先初始化控件
            //2、获取适配器
            //3、控件与适配器结合
            //4、MultiAutoCompleteTextView要设置分隔符
            String[] res = {"xiaoming","xiaohong","xiaolan","xiaoln"};
            acTV = (AutoCompleteTextView)findViewById(R.id.AutoCompleteTextView_name);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, res); 
            acTV.setAdapter(adapter);
            
            
            macTV = (MultiAutoCompleteTextView) findViewById(R.id.AutoCompleteTextView_name2);
            macTV.setAdapter(adapter);
            //设置分隔符
            macTV.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    
    

    这里simple_list_item_1实现的效果还是白字白底的,看不清,求请教怎么改

    相关文章

      网友评论

          本文标题:Android自动匹配输入控件AutoCompleteTextV

          本文链接:https://www.haomeiwen.com/subject/swlxuxtx.html