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 |
Tags
- Spinner
- 코틀린
- 왕초보
- 시큐어코딩
- React
- snowpack
- 답글
- 스타일보험
- 상속
- Android
- 버전일치
- kotlin
- 오버라이드
- FIle
- degit
- 미니게임
- parcel
- java#왕초보
- java
- 게시판
- 숫자
- webpack
- 스프링
- Spring
- git
- 쿠키
- sub query
- SQL
- 안드로이드
- 함수
Archives
- Today
- Total
YSHUSH
Rating bar 본문
Rating bar를 조작하면
별의 갯수가 텍스트뷰에 보여지도록 해보자
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.0"
android:textSize="30sp"
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.418"
android:id="@+id/textView"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:stepSize="1"
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. MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val ratingBar = findViewById<RatingBar>(R.id.ratingBar)
val textView = findViewById<TextView>(R.id.textView)
ratingBar.setOnRatingBarChangeListener{ ratingBar, rating, fromUser->
textView.text = "$rating"
}
}
}
'Coding > Android(kotlin)' 카테고리의 다른 글
File (0) | 2022.02.10 |
---|---|
Counter(숫자 세기 미니 프로그램) (0) | 2022.02.08 |
Seek bar (0) | 2022.02.08 |
Navigation menu (0) | 2022.02.08 |
Fragment (0) | 2022.02.08 |