Skip to content

Instantly share code, notes, and snippets.

View theerasan's full-sized avatar

Theerasan Tonthongkam theerasan

View GitHub Profile
fun View.setOnAnimateClickListener(resId: Int?, onClick: (View) -> Unit) {
var secondaryView: View? = null
if (resId != null) {
secondaryView = this.findViewById(resId)
}
this.setOnClickListener({ view ->
Handler().postDelayed({
private fun initCardViewWithKotlinExtensionWay() {
val cardView2 = findViewById(R.id.card_view2) as CardView
cardView2.setOnAnimateClickListener(R.id.imageBackground2, { view ->
Toast.makeText(this, "Clicked " + view.id , Toast.LENGTH_SHORT).show()
})
}
// ViewExtension
fun View.setOnAnimateClickListener(onClick: (View) -> Unit) {
this.setOnAnimateClickListener(null, onClick)
}
// MainActivity
val applyButton = findViewById(R.id.applyButton)
applyButton.setOnAnimateClickListener({view ->
fun main(args: Array<String>) {
println(13.isPrimeNumber())
}
private fun Int.isPrimeNumber(): Boolean {
if (this < 1) return false
var count = 0
(1..this).forEach {
if (this%it == 0) count++
}
fun main(args: Array<String>) {
println("IPHONE AND ANDROID".reverseSentence())
}
private fun String.reverseSentence(): String {
val words = this.split(" ")
return words.map { it.reversed() }.joinToString { it }.replace(",", "")
}
fun main(args: Array<String>) {
var x = 10
var y = 3
println("Before Swapping x = ${x}, y = ${y}")
x += y
y = x - y
x -= y