자동완성텍스트뷰,멀티자동완성테스트뷰

2019. 3. 19. 14:03Andriod

# *.xml

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

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="선택하세요"
android:completionThreshold="2"
android:hint="자동완성텍스트뷰"/>

<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="선택하세요"
android:completionThreshold="2"
android:hint="멀티자동완성텍스트뷰"
/>
</LinearLayout>


# *.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.a0319;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
 
public class MainActivity extends AppCompatActivity {
    /* AdapterView
           - 위치: Adapter의 위치 => MainActivity,this
           - 데이터 : 한 개의 데이터에 적용될 n개 데이터
           - 1개에 대한 디자인인    */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        String[] items ={"CIS-뉴욕","CSI-라스베가스"," CSI-마이애미","Friends"
                        ,"Fringe""Lost"};
 
        // 자동완성텍스트뷰
        AutoCompleteTextView auto = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
 
        // 어댑터의 구성요소 => 위치 , 1개에 대한 디자인 , 데이터
        ArrayAdapter<String> addpter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line,items);
 
        // 어댑터 정렬
        auto.setAdapter(addpter);
 
        // 멀티자동완성텍스트뷰
        MultiAutoCompleteTextView multi = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
 
        MultiAutoCompleteTextView.CommaTokenizer token  = new MultiAutoCompleteTextView.CommaTokenizer();
 
        multi.setTokenizer(token);
        multi.setAdapter(addpter);
    }//onCreate
}
 
cs