<?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/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<AutoCompleteTextView
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="3"
/>
<!-- android:completionThreshold="3" 3글자 이상 입력시
(AutoCompleteTextView) 는 평소에 숨겨져 있다가 위에 조건이 만족하면 출력됨
여러개의 데이터를 표시할때는 listview가 좋다
-->
</LinearLayout>
package com.commonsware.android.selection9;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
public class AutoCompleteDemo extends Activity implements TextWatcher {
TextView selection;
AutoCompleteTextView edit;
String[] items = { "lorem", "ipsum", "dolor", "sit", "amet",
"consectueuer", "adipiscing", "elit", "morbi", "vel", "ligula",
"vitae", "arcu", "aliquet", "mollis", "etiam", "vel", "erat",
"placerat", "ante", "porttitor", "길다", "많다", "너무 많다", "너무 길다", };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
edit = (AutoCompleteTextView) findViewById(R.id.edit);
edit.addTextChangedListener(this);
//ArrayAdapter : AutoCompleteTextView 데이터 바인딩
//ArrayAdapter와 AutoCompleteTextView 연결
edit.setAdapter(new ArrayAdapter<string>(this,
android.R.layout.simple_dropdown_item_1line, items));
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
selection.setText(edit.getText());
}
}