####1、实现在输入框输入的时候,自动补全
界面绘制:
####2、逻辑代码
package com.example.menglux.myautocompletetextview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private AutoCompleteTextView mAutoCompleteTextView;
private List<String> mList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoComTv_id);
mAutoCompleteTextView.setThreshold(1);
mList = new ArrayList<String>();
mList.add("lili");
mList.add("lele");
mList.add("lum");
mList.add("abc");
mList.add("bca");
mList.add("cab");
/***
* 参数1 当前上下文
* 参数2 显示的匹配的布局
* 参数3 存储自动匹配的值数组, 也可以是字符串数组 如 String [] str = {"lili","hello","kitt"}; str
* */
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
this,
R.layout.support_simple_spinner_dropdown_item,
mList);
mAutoCompleteTextView.setAdapter(mAdapter);
}
}
####3、效果展示