代码如下:
public class MainActivity extends Activity {
private AutoCompleteTextView actv;
private static final String[] autoStrs = new String[] { "a", "abc", "abcde" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actv = (AutoCompleteTextView) findViewById(R.id.actv);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, autoStrs);
actv.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
代码如下:
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
AutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/actv"
android:completionThreshold="1" /!-- 设置只需要输入一个字就开始匹配 --
/LinearLayout