
Kotlin 숫자 구별을 위한 확장함수(Extension Function)
2022. 5. 17. 10:34
Android-Kotlin📱
코틀린에서 제공하는 클래스에 없는 기능을 직접 확장하여 기능을 구현한다. 함수가 기존 클래스에 추가되면 이를 확장 함수 라고 합니다. 확장함수는 기존 클래스의 메서드인 것처럼 호출이 가능하다. String클래스는 문자열을 다루며 문자열 내부에 있는 숫자가 있을 때 구별하지 못하여 예외처리에 불편함이 있다. ex) 비밀번호 설정시 숫자가 필수입력 ex) 전화번호, 계좌번호 숫자를 써야 할 때 (방지 할 수 있으나, 예외처리용) In PlayGround fun main() { var a = "1" if(a.isNumber().not()) { print("a는 숫자가 아닙니다") } else print("a는 숫자입니다.") //a는 숫자입니다. println("치킨 먹고싶다".isNumbe..

Kotlin BMI With ViewBinding (코틀린 뷰바인딩 BMI)
2022. 5. 17. 00:43
Android-Kotlin📱
키워드 : pow, binding, if(예외처리) activity_main.xml //진하게 //숫자만 입력가능 //결과 값을 출력해줄 TextView //사용자에게 보여지지 않으며 개발자에게만 예시로 보임 MainActivity.kt package com.example.bmi import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Toast import com.example.bmi.databinding.ActivityMainBinding import kotlin.math.pow import kotlin.math.roundToInt class MainActivity : AppCompat..

코틀린 뷰바인딩 Kotlin ViewBinding
2022. 5. 15. 21:38
Android-Kotlin📱
viewBinding findViewById을 대체하기 위한 것 뷰와 상호작용하는 코드를 쉽게 작성할 수 있으며 바인딩 클래스의 인스턴스에는 상응하는 레이아웃에 ID가 있는 모든 뷰의 직접 참조 대부분의 경우 viewBinding이 findViewById를 대체합니다. findViewById란? [layout] .xml 파일에서 지정한 id를 .kt에서 다룰 수 있게 참조하는 것 findViewById 단점 id와 view가 많아지게 되면 id value가 중복이 가능하지만 구별하기 힘들다. viewbinding 장점 1. Null safety - 뷰의 직접 참조를 생성하여 View ID로 인해 null pointer exception 발생 위험이 없다 2. Type safety - .XML파일에 참조하..

Kotlin Retrofit
2022. 5. 9. 11:19
Android-Kotlin📱
Retrofit 코틀린과 자바에서 사용하는 라이브러리, http 통신을 통해 서버에서 앱으로 API을 제공한다. https://square.github.io/retrofit/ Retrofit A type-safe HTTP client for Android and Java square.github.io build.gradle 내부 implementation 'com.squareup.retrofit2:retrofit:(insert latest version)' implementation 'com.squareup.retrofit2:converter-gson:(insert latest version)' implementation 'com.google.code.gson:gson:(insert latest vers..