自学android——AutoCompleteTextView的使用

在慕课网上学习的

AutoCompleteTextView

代码如下
package com.example.admin.test_20160306;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {
    private AutoCompleteTextView autoCompleteTextView;
    private String[] res={"skk1","skk2","skk3","skk4"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        autoCompleteTextView=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,res);
        autoCompleteTextView.setAdapter(adapter);
    }
}
layout很简单
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.admin.test_20160306.MainActivity">


    <AutoCompleteTextView
        android:completionThreshold="3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="New AutoCompleteTextView"
        android:id="@+id/autoCompleteTextView"
        android:textSize="20dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

这样就完成了

你可能感兴趣的:(android,String,Class)