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
- 버전일치
- 스프링
- java#왕초보
- 미니게임
- Spinner
- FIle
- 오버라이드
- Spring
- SQL
- snowpack
- 상속
- 게시판
- 안드로이드
- degit
- 답글
- sub query
- 왕초보
- kotlin
- Android
- git
- parcel
- 숫자
- 시큐어코딩
- 함수
- 스타일보험
- 쿠키
- webpack
- java
- React
- 코틀린
Archives
- Today
- Total
YSHUSH
Counter(숫자 세기 미니 프로그램) 본문
숫자 세는 미니 프로그램을 만들어보자
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/counter_num"
android:layout_width="474dp"
android:layout_height="63dp"
android:text="0"
android:gravity="center"
android:textSize="50sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintVertical_bias="0.091"/>
<Button
android:id="@+id/plus_btn"
android:text="+"
android:textSize="80sp"
android:layout_width="224dp"
android:layout_height="188dp"
app:layout_constraintBottom_toTopOf="@+id/reset_btn"
android:layout_marginBottom="44dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="60dp"
app:layout_constraintTop_toBottomOf="@+id/counter_num"
app:layout_constraintVertical_bias="1.0"/>
<Button
android:id="@+id/reset_btn"
android:textSize="30sp"
android:text="reset"
android:layout_width="471dp"
android:layout_height="63dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintVertical_bias="0.528"/>
<EditText
android:layout_width="333dp"
android:layout_height="47dp"
android:inputType="number"
android:text="0"
android:ems="10"
android:gravity="center"
android:id="@+id/editText"
app:layout_constraintTop_toBottomOf="@+id/reset_btn"
android:layout_marginTop="40dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="68dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.0"/>
<Button
android:text="set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/set_btn"
app:layout_constraintStart_toEndOf="@+id/editText"
android:layout_marginStart="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintTop_toBottomOf="@+id/reset_btn"
android:layout_marginTop="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.0"/>
<Button
android:id="@+id/minus_btn"
android:text="-"
android:textSize="80sp"
android:layout_width="224dp"
android:layout_height="188dp"
app:layout_constraintBottom_toTopOf="@+id/reset_btn"
android:layout_marginBottom="44dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="56dp"
app:layout_constraintTop_toBottomOf="@+id/counter_num"
app:layout_constraintVertical_bias="1.0"/>
</androidx.constraintlayout.widget.ConstraintLayout>
2. MainActivity,kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var counter:Int = 0
val counterNum = findViewById<TextView>(R.id.counter_num)
val plusBtn = findViewById<Button>(R.id.plus_btn)
val minusBtn = findViewById<Button>(R.id.minus_btn)
val resetBtn = findViewById<Button>(R.id.reset_btn)
plusBtn.setOnClickListener {
counter++
counterNum.text = counter.toString()
}
minusBtn.setOnClickListener {
counter--
counterNum.text = counter.toString()
}
resetBtn.setOnClickListener {
counter = 0
counterNum.text = "0"
}
val editText = findViewById<EditText>(R.id.editText)
val setBtn = findViewById<Button>(R.id.set_btn)
setBtn.setOnClickListener {
counterNum.text = editText.text
counter = editText.text.toString().toInt()
}
}
}
'Coding > Android(kotlin)' 카테고리의 다른 글
JSON (0) | 2022.02.10 |
---|---|
File (0) | 2022.02.10 |
Rating bar (0) | 2022.02.08 |
Seek bar (0) | 2022.02.08 |
Navigation menu (0) | 2022.02.08 |