public class MainActivity extends Activity {
private AutoCompleteTextView sName;
private MultiAutoCompleteTextView mName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// sName = (AutoCompleteTextView) this.findViewById(R.id.s_name);
mName = (MultiAutoCompleteTextView) this.findViewById(R.id.m_name);
String[] objects = new String[] { "老张", "老陈", "老谢", "老郑", "老鲁", "老黄",
"老林" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, objects);
// this.sName.setAdapter(adapter);
this.mName.setAdapter(adapter);
this.mName.setTokenizer(new Tokenizer() {
@Override
public CharSequence terminateToken(CharSequence text) {
System.out.println("terminateToken......");
System.out.println(text);
return null;
}
@Override
public int findTokenStart(CharSequence text, int cursor) {
System.out.println("findTokenStart.....");
System.out.println(text);
System.out.println(cursor);
return 0;
}
@Override
public int findTokenEnd(CharSequence text, int cursor) {
System.out.println("findTokenEnd.......");
System.out.println(text);
System.out.println(cursor);
return 0;
}
});
}
}
<RelativeLayout 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"
tools:context=".MainActivity" >
<!--
<AutoCompleteTextView
android:id="@+id/s_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1" />
-->
<MultiAutoCompleteTextView
android:id="@+id/m_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1" />
</RelativeLayout>