Android的文本提示框有两种方式:
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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="模糊查询" /> <AutoCompleteTextView android:id="@+id/autotext" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <MultiAutoCompleteTextView android:id="@+id/mull" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity.java文件
package cn.szy.com; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.MultiAutoCompleteTextView; public class MainActivity extends Activity { /** Called when the activity is first created. */ private MultiAutoCompleteTextView move; private AutoCompleteTextView auto; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); auto = (AutoCompleteTextView)this.findViewById(R.id.autotext); String [] autoStrings = new String [] { "联合国", "联合军", "联邦" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_dropdown_item_1line,autoStrings); auto.setAdapter(adapter) ; move = (MultiAutoCompleteTextView)this.findViewById(R.id.mull); move.setAdapter(adapter) ; move.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); } }