package com.example.exercise;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class ActActivity extends Activity{
AutoCompleteTextView autoCompleteTextView;
<span style="white-space:pre"> MultiAutoCompleteTextView multiAutoCompleteTextView;</span>
String[] data = {"chongqing1","chongqing2","chongqing3","xian1","xian2","xian3"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.auto_complete_textview);
autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ActActivity.this,
android.R.layout.simple_list_item_1, data);
autoCompleteTextView.setAdapter(adapter);
<span style="white-space:pre"> multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.macTextView);
<span style="white-space:pre"> </span>multiAutoCompleteTextView.setAdapter(adapter);
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 设置搜索的分隔符位逗号
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());</span>
}
}
<?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/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入您要搜索的关键字"
android:completionThreshold="2" >
</AutoCompleteTextView>
<MultiAutoCompleteTextView
android:id="@+id/macTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="请输入您要发送的邮箱名"
android:completionThreshold="2"
/>
</LinearLayout>
<activity android:name="com.example.exercise.ActActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>