很多textField里面都有这种自动提示的功能:
当你输入一个字母或者一个汉字时会自动显示一些提示的信息:
package com.ko8e;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
public class MyActivity extends Activity {
/** Called when the activity is first created. */
private static final String[] nContent = { "zhuo", "kobe", "zhuori",
"kobebryant", "ko8e", "ko8ebryant" };
private AutoCompleteTextView autoView = null;
private TextView view = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, nContent);
view = (TextView) findViewById(R.id.view);
autoView = (AutoCompleteTextView) findViewById(R.id.autoView);
view.setText(R.string.hello);
// 将adapter添加到AutoCompleteTextView中
autoView.setAdapter(adapter);
}
/* protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.autoView);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};*/
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<AutoCompleteTextView
android:id="@+id/autoView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>