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("");
}

});
}
}

XML文件如下:

<?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:id="@+id/textView"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:layout_gravity
="center_horizontal"
android:text
="请输入"
android:textSize
="20px" >
</TextView>

<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView"
android:layout_width
="260px"
android:layout_height
="wrap_content"
android:layout_gravity
="center_horizontal"
android:text
="" />

<Button
android:id="@+id/btn"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:layout_gravity
="center_horizontal"
android:text
="清除" >
</Button>

</LinearLayout>

 

 

运行效果如下

 



 

posted on 2012-01-15 14:30  C语言答疑课堂  阅读(451)  评论(0编辑  收藏  举报