android:AutoCompleteTextView和MultAutoCompleteTextView的簡單使用

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>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章