Android组件 输入框自动提示(AutoCompleteTextView)

/res/layout/main.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <AutoCompleteTextView 
        android:id="@+id/autoCompleteTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入信息"/>
</LinearLayout>

Java代码如下:

package com.demo.android.autoCompleteTextView;

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

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        autoCompleteTextView=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        ArrayAdapter adapter=new ArrayAdapter(MainActivity.this, android.R.layout.simple_dropdown_item_1line,autoStr);
        autoCompleteTextView.setAdapter(adapter);
    }
    
    private AutoCompleteTextView autoCompleteTextView;
    private String[] autoStr=new String[]{"ab","abc","abcd","def"};
}



 

你可能感兴趣的:(Android组件 输入框自动提示(AutoCompleteTextView))