布局文件\res\layout\main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="@+id/auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="下拉提示"
android:completionThreshold="1"
android:dropDownHorizontalOffset="10dp" />
<MultiAutoCompleteTextView
android:id="@+id/mauto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1" />
</LinearLayout>
代码部分:
public class AutoCompleteTextViewTest extends Activity {
AutoCompleteTextView actv;
MultiAutoCompleteTextView mactv;
String[] arr = { "我的android", "我的CSDN", "我的博客", "java", "Java", "android" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, arr);
actv = (AutoCompleteTextView) findViewById(R.id.auto);
actv.setAdapter(aa);
mactv = (MultiAutoCompleteTextView) findViewById(R.id.mauto);
mactv.setAdapter(aa);
// 设置分隔符
mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}
效果图01,输入“我的”:
效果图02,删除“我的”,输入“java”:
效果图03,第二个编辑框中输入“我的”:
效果图04 & 效果图05,第二个编辑框中输入“我的”,并选中“我的android”,之后继续输入“and”,选择第一条“android”: