Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- sub query
- 시큐어코딩
- 안드로이드
- 버전일치
- kotlin
- 쿠키
- parcel
- React
- 답글
- Spring
- webpack
- java#왕초보
- 게시판
- degit
- Android
- FIle
- 숫자
- git
- 오버라이드
- 상속
- Spinner
- 코틀린
- 스타일보험
- SQL
- 스프링
- java
- 미니게임
- snowpack
- 왕초보
- 함수
Archives
- Today
- Total
YSHUSH
Spinner2 본문
1. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="선택결과"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.591"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
2. build.gradle에 추가(Sync Now 꼭 해주기)
buildFeatures{
viewBinding true
}
3. app - src - res - layout 우클릭후 새로만들기 - XML - Layout XML File - item_spinner로 생성
item_spinner
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tvItemSpinner"
android:layout_width="match_parent"
android:layout_height="45dp"
android:paddingTop="10dp"
android:paddingStart="30dp"
android:textColor="@android:color/black"
android:textSize="15sp"
android:paddingLeft="30dp"/>
4. MainActivity.kt
class MainActivity : AppCompatActivity() {
val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//setContentView(R.layout.activity_main)
setContentView(binding.root)
var data = listOf("선택하세요", "1월", "2월", "3월", "4월", "5월", "6월")
var adapter = ArrayAdapter<String>(this, R.layout.item_spinner, data)
binding.spinner.adapter = adapter
binding.spinner.onItemSelectedListener = object :AdapterView.OnItemSelectedListener{
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, pos: Int, p3: Long) {
binding.result.text = data.get(pos)
}
override fun onNothingSelected(p0: AdapterView<*>?) {
}
}
}
}
'Coding > Android(kotlin)' 카테고리의 다른 글
Navigation menu (0) | 2022.02.08 |
---|---|
Fragment (0) | 2022.02.08 |
Spinner (0) | 2022.02.08 |
Context menu (0) | 2022.02.08 |
체크박스 (0) | 2022.02.08 |