AutoCompleteTextViewとM u l tiAutoCompleteTextViewの使用の詳細
2563 ワード
コントロールコード:
Activityコード:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".UIDemoActivity" >
<AutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView1"
android:hint="@string/completeTextView1Hint"
android:completionThreshold="2"
>
</AutoCompleteTextView>
<MultiAutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/multiAutoCompleteTextView1"
android:hint="@string/completeTextView1Hint"
android:completionThreshold="1"
>
</MultiAutoCompleteTextView>
</LinearLayout>
Activityコード:
package com.werw.UIDemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
/**
* @author frank
*
*/
public class UIDemoActivity extends Activity {
private AutoCompleteTextView acTextView;
private MultiAutoCompleteTextView macTextView;
private String[] res = {"hhb","wz","gh","gmm","nsb","abc","ab2"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*
*
*
* ,
*
*/
acTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
macTextView = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,res);
acTextView.setAdapter(adapter);
macTextView.setAdapter(adapter);
//
macTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}