Android实现多个词汇连续输入的提示
<MultiAutoCompleteTextView
android:id="@+id/mulauto"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
java:
package com.just;
import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
public class MainActivity extends Activity {
private static final String[] autostr = new String[] { "Italy" , "IT" ,
"item", "its" , "itseif" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
ArrayAdapter<?> adapter = new ArrayAdapter<Object>(this,
android.R.layout. simple_dropdown_item_1line, autostr );
MultiAutoCompleteTextView multview = (MultiAutoCompleteTextView) findViewById(R.id.mulauto );
multview.setAdapter(adapter);
multview.setTokenizer( new MultiAutoCompleteTextView.CommaTokenizer());
}
}
与之前的实现不同的是在实现选择输入的还要设置一个分词方式(Tokenizer);