[url]http://imshare.iteye.com/blog/771539[/url]
[url]http://windywindy.iteye.com/blog/464152[/url]
MultiAutoCompleteTextView也是具有自动完成提示的功能,它和AutoCompleteTextView的区别就是[color=red]MultiAutoCompleteTextView可以在输入框中一直增加新的选取值。编写方式也有所不同,在进行setAdapter之后还需要调用setTokenizer(),否则会出现错误[/color]
[url]http://windywindy.iteye.com/blog/464152[/url]
MultiAutoCompleteTextView也是具有自动完成提示的功能,它和AutoCompleteTextView的区别就是[color=red]MultiAutoCompleteTextView可以在输入框中一直增加新的选取值。编写方式也有所不同,在进行setAdapter之后还需要调用setTokenizer(),否则会出现错误[/color]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" >
<requestFocus />
</AutoCompleteTextView>
<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
package pandy.auto.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
public class AutoCompleteTestActivity extends Activity {
private AutoCompleteTextView autoCompleteTextView1;
private MultiAutoCompleteTextView multiAutoCompleteTextView1;
private String[] allData = new String[]{"China","Russia","Germany",
"Ukraine","Belarus","USA","China1","China2","USA1"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
autoCompleteTextView1 = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
multiAutoCompleteTextView1 = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line,allData);
autoCompleteTextView1.setAdapter(adapter);
autoCompleteTextView1.setThreshold(1);
multiAutoCompleteTextView1.setAdapter(adapter);
multiAutoCompleteTextView1.setThreshold(1);
multiAutoCompleteTextView1.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}