您的位置:首页 > 移动开发 > Android开发

android:AutoCompleteTextView和MultAutoCompleteTextView的简单使用

2016-04-19 19:56 579 查看
package com.example.exercise;

import android.app.Activity;
import android.os.Bundle;

import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class ActActivity extends Activity{
AutoCompleteTextView autoCompleteTextView;
<span style="white-space:pre">	MultiAutoCompleteTextView multiAutoCompleteTextView;</span>
String[] data = {"chongqing1","chongqing2","chongqing3","xian1","xian2","xian3"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.auto_complete_textview);
autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ActActivity.this,
android.R.layout.simple_list_item_1, data);
autoCompleteTextView.setAdapter(adapter);
<span style="white-space:pre">		multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.macTextView);
<span style="white-space:pre">		</span>multiAutoCompleteTextView.setAdapter(adapter);
<span style="white-space:pre">		</span>/**
<span style="white-space:pre">		</span> * 设置搜索的分隔符位逗号
<span style="white-space:pre">		</span> */
<span style="white-space:pre">		</span>multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());</span>
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入您要搜索的关键字"
android:completionThreshold="2" >

</AutoCompleteTextView>
<MultiAutoCompleteTextView 
        android:id="@+id/macTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="请输入您要发送的邮箱名"
        android:completionThreshold="2"
        />
</LinearLayout>


<activity android:name="com.example.exercise.ActActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android textview