Android AutoCompleteTextView用法
package com.turboradio.googlesdk;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class Ex_4_13 extends Activity {
private static final String [] autoStr = {
"a","abc","abcd","acd"
};
private AutoCompleteTextView autoText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ex_4_13);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,autoStr);
autoText = (AutoCompleteTextView)findViewById(R.id.auto);
autoText.setAdapter(adapter);
}
}
ex_4_13.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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入"
/>
<AutoCompleteTextView
android:id="@+id/auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>