动态自动匹配

1.AutoCompleteTextView:动态匹配输入的内容,如百度搜索引擎当输入文本时可以根据内容显示匹配的热门信息。

属性:completionThreshold=“2”  //设置输入多少字符时自动匹配

autoComleteTextView.java

package com.example.xuhai.test;

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

/**
 * Created by xuhai on 2016/8/4.
 */
public class autComlpeteTextView extends Activity{
    private AutoCompleteTextView actv;
    private String[] array={"beijing1","beijing2","yuncheng1","yuncheng2","nancheng"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.auocompletetextview);
        /*
        *第一步:初始化控件
         第二步:需要一个适配器
         第三步:初始化数据源----这个数据源去匹配文本框输入的内容
         第四步:将adpter与当前的AutoCompleteTextView绑定
        */
        actv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
        ArrayAdapter<String> adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,array);
        actv.setAdapter(adapter);
    }
}
autocompleteviewtext.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <AutoCompleteTextView
        android:completionThreshold="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="请输入你要查找的内容"
        android:id="@+id/autoCompleteTextView"
        android:layout_gravity="center_horizontal" />
    </LinearLayout>
运行结果


2.MultiAutoCompleteTextView:支持选择多个值(在多次输入的情况下),分别用分隔符隔开,并且在每个值选中的时候再次输入值时会自动去匹配,可用在发短信,发邮件的时候选择联系人这种类型中。

属性:completionThreshold=“2”;//设置输入多少字符时自动匹配

mtxt.setTokenizer(new MultiAutoCompleteTextView.commaTokenizer());//设置分隔符(这里是设置逗号分隔))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值