언어 : kotlin 사용
Android studio 사용
MainActivity.kt
package com.example.gradetest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.*
import com.example.gradetest.databinding.ActivityMainBinding
import android.view.View
class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener {
lateinit var binding : ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.btnConvert.setOnClickListener{
var input = binding.txtInput.text.toString().toDouble()
val res = input * 1.6
binding.txtResult.text = res.toString()
}
}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
}
override fun onNothingSelected(p0: AdapterView<*>?) {
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<Button
android:id="@+id/btnConvert"
android:layout_width="180dp"
android:layout_height="72dp"
android:layout_marginTop="132dp"
android:text="Convert"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtInput" />
<TextView
android:id="@+id/txtResult"
android:layout_width="117dp"
android:layout_height="82dp"
android:layout_marginStart="56dp"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnConvert"
app:layout_constraintVertical_bias="0.45" />
<TextView
android:id="@+id/textView2"
android:layout_width="100dp"
android:layout_height="58dp"
android:layout_marginTop="196dp"
android:layout_marginEnd="16dp"
android:text="mile"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="159dp"
android:layout_height="56dp"
android:layout_marginBottom="112dp"
android:text="km입니다."
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.303"
app:layout_constraintStart_toEndOf="@+id/txtResult" />
<EditText
android:id="@+id/txtInput"
android:layout_width="220dp"
android:layout_height="60dp"
android:layout_marginTop="196dp"
android:ems="10"
android:gravity="right"
android:inputType="textPersonName"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.193"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
'수업' 카테고리의 다른 글
모바일프로그래밍 - LifeCycleFragment (0) | 2023.03.28 |
---|---|
모바일프로그래밍 - LifeCycle (0) | 2023.03.27 |
컴퓨터그래픽스 - 5. OpenGL 개요, 구성 요소, freegult 설치 (0) | 2023.03.27 |
컴퓨터그래픽스 - 4. 그래픽스 API (+Cortona3D 설치) (0) | 2023.03.27 |
웹프로그래밍 - 3.1 가상클래스와 가상 요소 (0) | 2023.03.26 |