Android/Kotlin 49

람다식(Lambda Expression) & 익명함수(Anonymous Function)

1. 람다식 & 익명함수 fun main(args: Array){ val instantFunc: (Int) -> Unit = { number:Int -> println("값: $number") } instantFunc(1) instantFunc.invoke(1) val instantFunc2: (Int) -> Unit = fun(number:Int): Unit{ println("값: $number") } instantFunc2(2) instantFunc2.invoke(2) } 2. it식별자fun main(args: Array){ val instantFunc: (Int)-> Unit = { println("값: $it") } instantFunc }람다식의 매개변수가 하나뿐일 때 3. 안드로이드에서의 예시

Android/Kotlin 2018.12.09

캐스팅(Casting)

1.업캐스팅(Upcasting)open class Person(val name: String, val age: Int) class Student(name: String, age: Int, val id: Int): Person(name, age) fun main(args: Array){ val p1: Person = Student("선필", 30, 2013210059) } 출처: 초보자를 위한 Kotlin 200제, 정보문화사. p177 슈퍼클래스타입은 항상 슈퍼클래스 자체나 서브클래스의 인스턴스만 가질 수 있다. 2.as 연산자와 다운캐스팅open class Person(val name: String, val age: Int) class Student(name: String, age: Int, val i..

Android/Kotlin 2018.12.09

ExoPlayer

인도형님 유튜브: https://www.youtube.com/watch?v=HZuWeJ_Sa5A공식사이트: https://google.github.io/ExoPlayer/ 1.Gradleimplementation 'com.google.android.exoplayer:exoplayer:2.9.1'이걸 하니까 implementation 'com.android.support:appcompat-v7:27.1.1'이 부분에서 에러가 났는데 버전을 똑같이 27.1.1로 바꿔주니까 된다. compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }이 부분을 꼭 넣어줘야 한다. androi..

Android/Kotlin 2018.11.28

그래픽 라이브러리 없이 Retrofit만 사용하여 이미지 출력

1. Gradleimplementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0' 2. Permission 3. Interface(Retrofit)interface RetrofitImageAPI { @GET("api/RetrofitAndroidImageResponse") fun getImageDetails(): Call } 4. MainActivity.ktclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedIns..

Android/Kotlin 2018.11.28

[문법] While문에서 assignment 불가능

while ((c = inputStream!!.read()) != -1) { outputStream.write(c) }이거 안되서 한참 고민. Kotlin은 while안에서 assign이 안된다. do{ c = inputStream.read() outputStream.write(c) } while(c != -1)이렇게 고치면 가능. 사람들은 이런 의견을 내고 있다. Wasabi375May 11The Kotlin team decided against it for a few reasons I think. In most cases it is just considered bad style and it also makes code harder to read. Yes your example is the one va..

Android/Kotlin 2018.11.25

[Kotlin] Retrofit

코틀린으로 구현한 Retrofit.공식사이트: https://square.github.io/retrofit/ 1.Gradleimplementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0'두개의 버전은 일치시켜 준다. 2.Manifests 3.XML버튼 두개 만들어준다. 3.RetrofitService.ktdata class ResponseDTO(var result:String? = null) interface RetrofitService{ //post @FormUrlEncoded @POST("/test") fun postRequest(@Field("id") id:..

Android/Kotlin 2018.11.24

Glide

*Glide Document: https://bumptech.github.io/glide/ 버전이 올라가면서 예전에 쓰던거에서 사용법이 약간 바뀌었다.implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' implementation 'jp.wasabeef:glide-transformations:4.0.1'(세번째꺼는 Glide확장판? 같은 거) 1.PlaceholderGlide.with(this) .load("경로") .apply(RequestOptions().placeholder(R.drawable.s1)) .into(main_iv) 2.Center..

Android/Kotlin 2018.11.24