AutoCompleteTextView

AutoCompleteTextView

<AutoCompleteTextView
    android:id="@+id/autoCompleteTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="请输入要搜索的内容"
    android:completionHint="指定提示标题"
    android:completionThreshold="1"
    />
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 关联布局文件
        setContentView(R.layout.activity_main);
        // 继承自EditText
        mAutoCompleteTextView = (AutoCompleteTextView) findViewById(
                R.id.autoCompleteTextView);
        String[] currentInput = new String[] { "a", "ab", "abc", "abcd",
                "abcde" };
        // 创建适配器
        ArrayAdapter arrayAdapter = new ArrayAdapter(this,
                R.layout.array_item, currentInput);
        // 设置适配器
        mAutoCompleteTextView.setAdapter(arrayAdapter);
    }

AutoCompleteTextView_第1张图片

你可能感兴趣的:(Android)