결과화면

 

 package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;

public class AutoTextDemo extends Activity {
 String[] items = {"SM3", "SM5", "SM7", "SONATA", "K3", "K5", "K7", "SOUL", "SORENTO"};
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.autotext_demo);
  
  //AutoCompleteTextView - 자동완성 1개만 해줌...
  AutoCompleteTextView auto1 = (AutoCompleteTextView)findViewById(R.id.autotext1);
  auto1.setAdapter(new ArrayAdapter<String>(
    this, android.R.layout.simple_dropdown_item_1line, items
  ));
  
  
  //MultiAutoCompleteTextView - 자동완성 여러개 해줌...
  MultiAutoCompleteTextView auto2 =
    (MultiAutoCompleteTextView)findViewById(R.id.autotext2);
  auto2.setAdapter(new ArrayAdapter<String>(
    this, android.R.layout.simple_dropdown_item_1line, items
  ));
  
  auto2.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
 }
}

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <AutoCompleteTextView
        android:id="@+id/autotext1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="pick a item"
        android:completionThreshold="2" />

    <MultiAutoCompleteTextView
        android:id="@+id/autotext2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="pick a item"
        android:completionThreshold="2" />

</LinearLayout>

 

'2020년도 이전 > [WebSig] Android' 카테고리의 다른 글

ProgressBar Demo1  (0) 2013.08.13
Image Demo  (0) 2013.08.13
Spinner Demo  (0) 2013.08.13
Button Demo  (0) 2013.08.13
EditText Demo  (0) 2013.08.13

+ Recent posts