본문 바로가기

Dead Code/DEPRECATED-KOTLIN

(49)
[코틀린코드연습장] ListView * CustomAdapter 원하는 기능을 adapter에 만들기텍스트뷰 2개와 버튼 2개로 이루어진 커스텀아답터를 만드는 코드입니다. class MainActivity : AppCompatActivity() { var data1 = arrayOf("text01","text02","text03","text04","text05","text06","text07","text08") var data2 = arrayOf("string01", "string02","string03","string04","string05","string06","string07","string08") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setC..
[코틀린코드연습장] ListView - adapter ListView는 아답터를 활용해야 함 package com.example.skynet.a016listview import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport android.widget.AdapterViewimport android.widget.ArrayAdapterimport kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { // adapter에 삽입할 에러이 생성 var list = arrayOf( "리스트1","리스트2","리스트3","리스트4","리스트5"..
[코틀린코드연습장] ImageView 이미지는 기본적으로 drawable 폴더에 저장 setImageResource 로 불러들일 수 있음 (R.drawable 로 파일명 지정) package com.example.skynet.a015imageview import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout..
[코틀린코드연습장] seekBar 프로그레스 바와 거의 동일OnSeekBarChangeListener는 3개의 메소드를 호출해야 함 2개 이상의 메소드를 호출할 때는 람다식이 아닌 익명 중첩클래스 사용seekBar2.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{}) package com.example.skynet.seekbar import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.widget.SeekBarimport kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivi..
[코틀린코드연습장] progressBar 프로그레스바의 특정값으로 증감incrementProgressBy 프로그레스바를 특정값으로 지정progress package com.example.skynet.progressbar import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // ..
[코틀린코드연습장] radioButton 라디오버튼은 라디오 그룹을 만들어 생성해야 함라디오 그룹내에서 라디오 그룹을 찾기 : checkedRadioButtonId라디오버튼 상태가 변경되었을때 이벤트 : OncheckedChangeListener package com.example.skynet.textview import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport android.widget.CompoundButtonimport android.widget.RadioGroupimport android.widget.TextViewimport kotlinx.android.synthetic.main.activity_main.*i..
[코틀린코드연습장] radioButton 라디오 버튼의 상태 체크 : ischecked라디오 버튼의 상태 반전 : toggle()상태가 변경될때마다의 이벤트 : OncheckedChangeListener package com.example.skynet.textviewimport android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport android.widget.CompoundButtonimport android.widget.TextViewimport kotlinx.android.synthetic.main.activity_main.*import org.w3c.dom.Textclass MainActivity : AppCompatActiv..
[코틀린코드연습장] Button 리스너를 만든다. 버튼 객체를 리스너와 연결한다. inner class를 사용하거나, 람다식을 사용한다. 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879package com.example.skynet.textview import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport android.widget.TextViewimport kotlinx.android.synthe..
[코틀린코드연습장] textview TextView 에 문자를 넣어보자. 1) 자바와 다르게 findViewById 과정이 필요없다.2) .setText("String") 과 .text ="String" 은 동일하게 작동 123456789101112131415161718192021222324252627package com.example.skynet.textview import android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport android.widget.TextViewimport kotlinx.android.synthetic.main.activity_main.*import org.w3c.dom.Text class MainA..
[코틀린코드연습장] 안드로이드 리스트뷰 생성 udemy 강좌를 보다가 까먹을것만 같아... 기재 리스트에 리스트로 활용할 array를 구성한다. 리스트뷰를 처음 만들 때,adapter를 설정하여, 리스트뷰의 adapter로 정의한다. * onitemClickListener : 리스트를 클릭했을 때, 발생 이벤트 정의 package com.example.james.udemy import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.AdapterView import android.widget.ArrayAdapter import kotlinx.android.synthetic.main.activity..
[코틀린코드연습장] 클래스...함수 오버라이딩(?) 클래스. 상속 받고 싶으면 상속대상 클래스는 open으로 기재 함수도 open으로 기재. 불러올때 override, super로 기재 12345678910111213141516171819fun main(args: Array) { val x : B = B() println(x.f(6,6))}open class A { open fun f(x:Int,y:Int):Int { println("first class") return x * y }}class B:A() { override fun f(x:Int,y:Int):Int { println("second class") println(super.f(x,y)) return x % y }} 결과 : second classfirst class360 inner class..
[코틀린코드연습장] listOf, filter, add var 를 사용한 리스트에는 값을 추가할 수 있다.val 을 사용한 리스트에는 값을 추가할 수 없다. 리스트 작성은 listOf 로 가능하며, listOf 로 작성된 리스트는 immutalbe하다. 값을 추가하기 위해서는 mutableListOf 로 작성이 되어야한다. mutableListOf 로 작성된 리스트는 add를 통해 단일 값을 추가 가능하고,addAll을 통해 리스트를 추가 할 수 있다. 또한 필터를 사용할 수 있다. 1234567fun main(args: Array) { var list = mutableListOf(1,2,4,5,6,7,8,10,12,31) var list2 = mutableListOf(100,200,300,400) list.addAll(list2) var listFilter..
[코틀린코드연습장] mapOf, Stringbuilder, append, insert mapOf : map으로 구성된 텍스트를, forEach 키워드를 통해 확인 가능, it 키워드를 사용할 수 있다.StringBuilder : StringBuilder를 통해 append를 자유롭게 할 수 있다. 자바에서는 StringBuffer라고 했던가. 12345678910111213fun main(args: Array) { var map = mapOf("key" to "value", "key2" to "value2") map.forEach{ println("${it.key}, ${it.value}") } var Txt = "abcdef" var builder: StringBuilder? = StringBuilder() builder?.append(" + plus 1") builder?.append..
[코틀린코드연습장] equals, indexOf, replace, substring, toUpperCase 간단한 텍스트 명령 - equals : 두개의 Stirng이 동일한지 확인 -> String- indexOf : 특정 문자(단어)의 시작점 확인 -> Int- replace : 특정 문자 바꾸기 -> String- substring : 시작점과 끝점을 지정하면 해당 String 반환 -> String- toUpperCase : 대문자로 변경 -> String 123456789101112131415161718fun main(args: Array) { var a:String = "hello" var b:String = "hello" var k = a.equals(b) var AandB = a+b var IndexAandB:Int = AandB.indexOf("l") var change:String = Aan..
[코틀린코드연습장] 메뉴얼에 나오는 기본 문법4 Break and Continue Labels1. Break + @Label로 특정 조건에서 Loop를 멈춘다. 12345678fun main(args: Array) { loop@ for (i in 1..5) { for (j in 1..3){ println("$i,$j") if (i == 3) break@loop } }}Colored by Color Scriptercs결과 : 1,1 1,2 1,3 2,1 2,2 2,3 3,1
[코틀린코드연습장] 메뉴얼에 나오는 기본 문법3 Execute if not nullnull 값이 아닐 경우에만 실행123456789val value = "a"fun main(args: Array) { value?.let { print("is not null") } if (value == null) { print("is null") }}cs결과 : is not null Map nullable value if not nullnull 값을 가질 수 있을 경우, 대체 텍스트를 입력할 수 있음*null이 아닐 경우1234fun main(args: Array) { val value = "abcde" val mapped = value?.let { print("value($value) is not null") } ?: print("value is null")}Col..
[코틀린코드연습장] 메뉴얼에 나오는 기본 문법2 Traversing a map/list of pairsmap을 활용하여, for loop를 만든다. 123456var map = mapOf("apple" to "Fruit", "lion" to "animal")fun main(args: Array) { for ((x, y) in map) { println("$x -> $y") }}Colored by Color Scriptercs 결과 : apple -> Fruitlion -> animal Using ranges'in' 을 통해서 range를 설정한다.'..'는 몹시 생소함 12345678910111213141516171819202122232425 var map = mapOf("apple" to "Fruit", "lion" to "animal")fun ma..
[코틀린코드연습장] 구구단 짜기 매번 프로그램 시작하면 해보는 구구단 짜기를 해본다. 12345678910fun main(args: Array) { for (x in 1..9) for (y in 1..9) if (y !== 9) { print("$x * $y = ${x * y} ") } else { println("$x * $y = ${ x*y } ") }}Colored by Color Scriptercs 생각보다 어렵지 않다. 결과 : 1 * 1 = 1 1 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5 1 * 6 = 6 1 * 7 = 7 1 * 8 = 8 1 * 9 = 9 2 * 1 = 2 2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 ..
[코틀린코드연습장] 메뉴얼에 나오는 기본 문법1 뭐든 처음부터 되는건 없다.코틀린의 코드는 나에게는 역시 암호다.설명서를 한번 보자 Default values for function parameters함수에 파라미터를 정의하는 코드이다. 123 fun foo(a: Int = 0, b: String = "") { ... } Colored by Color Scriptercs Filtering a list리스트에 필터를 걸어서 출력을 한다. 123456val list = listOf(1,2,3,4,5)val positives = list.filter { x -> x > 3 }// 또는 val positives = list.filter { it > 3 }fun main(args: Array) { println(positives)}Colored by Color..