package cn.com.sxp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.MultiAutoCompleteTextView;
public class MultiAutoActivity extends Activity {
private MultiAutoCompleteTextView autoCom = null;;
private Button btnClear = null;
private String[] normalString = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
normalString = new String[] { "android", "android sxp", "sxp", "sxp wx"};
autoCom = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView);
btnClear = (Button) findViewById(R.id.btn);
// simple_dropdown_item_1line
// android 简单的一些样式,貌似是自定义的
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, normalString);
autoCom.setAdapter(adapter);
// setTokenizer();
// Sets the Tokenizer 标记生成器 that will be used to determine the relevant range of the text where the user is typing.
// CommaTokenizer():
// 这个简易的组件可以用于一些列表中,这些列表包含被逗号以及一个或数个空格断开的项目。
// 不太理解,这个方法不加的话没法自动完成文本;添加的话又觉得是废话,列表当然以逗号分隔了
autoCom.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
btnClear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
autoCom.setText("");
}
});
}
}