Android/4. 고급 위젯
Day 110 : 기타 위젯
pancakemaker
2022. 3. 28. 13:09
1. 자동 완성 텍스트 뷰 / 멀티 자동 완성 텍스트 뷰
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView1"
android:completionHint="선택하세요"
android:completionThreshold="2"
android:hint="자동완성텍스트뷰">
</AutoCompleteTextView>
<MultiAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/multiAutoCompleteTextView1"
android:completionHint="선택하세요"
android:completionThreshold="2"
android:hint="멀티자동완성텍스트뷰"/>
</LinearLayout>
package com.cookandroid.project6_1_1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] items = {"CSI-뉴욕", "CSI-라스베가스", "CSI-마이애미", "Friends",
"Fringe", "Lost"};
//자동완성텍스트뷰 설정
AutoCompleteTextView auto = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
//뷰와 데이터 연결 - 자동완성텍스트뷰에 items 배열의 내용 출력
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, items);
auto.setAdapter(adapter);
//멀티자동완성텍스트뷰 설정
MultiAutoCompleteTextView multi = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
//다중 선택을 콤마로 구분
MultiAutoCompleteTextView.CommaTokenizer token = new MultiAutoCompleteTextView.CommaTokenizer();
multi.setTokenizer(token);
multi.setAdapter(adapter);
}
}
2. ProgressBar / SeekBar / RatingBar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ProgressBar ↓"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:progress="20"
android:secondaryProgress="50"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SeekBar ↓"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="20"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RatingBar ↓"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3"
android:stepSize="0.5"/>
</LinearLayout>