(一)概述
(二)相关属性
比如,火星1号—>你输入“火”—->会提示火星1号,而你输入1号—–>却不糊提示火星1号
(三)代码实现案例
运行效果:
实现代码:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android_autocompletetextview.MainActivity" >
<TextView
android:id="@+id/myTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AutoCompleteTextView" />
<AutoCompleteTextView
android:id="@+id/myAutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/myTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MultiAutoCompleteTextView" />
<MultiAutoCompleteTextView
android:id="@+id/myMultiAutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
private AutoCompleteTextView attv;//输入内容后自动提示功能的控件
private MultiAutoCompleteTextView mattv;//多个AutoCompleteTextView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
attv = (AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView);
//数据源
String autoStrings[]= new String[]{"火星1号","火星2号","火星3号","火星4号","apple","Sunner","Sunning","Sun"};
//第二个参数表示适配器的下拉风格
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_dropdown_item_1line,autoStrings);
//绑定适配器
attv.setAdapter(adapter);
mattv = (MultiAutoCompleteTextView) findViewById(R.id.myMultiAutoCompleteTextView);
mattv.setAdapter(adapter);
mattv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());// 完成对选项的拆分的功能,以逗号进行拆分
}
}
一些可能会用到的布局属性:
<完>