提交 056a0bd9 编写于 作者: 门心叼龙's avatar 门心叼龙

code perfect

上级 5beffe79
......@@ -34,6 +34,6 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation project(':lib_common')
}
......@@ -2,27 +2,57 @@ package com.fly.tour.test
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.fly.tour.common.util.ToastUtil
import com.fly.tour.test.view.MyView2
import com.fly.tour.test.view.Person1
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class MainActivity : AppCompatActivity() {
val TAG = "MYTAG"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn.setOnClickListener{ v -> ToastUtil.showToast("ok") }
btn.setOnClickListener(){ v -> ToastUtil.showToast("ok") }
//testOnClick()
//testThread()
//test1
Log.e(TAG, "主线程id:${mainLooper.thread.id}")
val job = GlobalScope.launch {
delay(6000)
Log.e(TAG, "协程执行结束 -- 线程id:${Thread.currentThread().id}")
}
Log.e(TAG, "主线程执行结束")
}
private fun testThread() = runBlocking {
repeat(8) {
Log.e("TAG", "协程执行$it 线程id:${Thread.currentThread().id}")
delay(1000)
}
}
val test1 = runBlocking {
repeat(8) {
Log.e("TAG", "协程执行$it 线程id:${Thread.currentThread().id}")
delay(1000)
}
}
private fun testOnClick() {
btn.setOnClickListener { v -> ToastUtil.showToast("ok") }
btn.setOnClickListener() { v -> ToastUtil.showToast("ok") }
btn.setOnClickListener({ v -> ToastUtil.showToast("ok") })
btn.setOnClickListener { }
btn.setOnClickListener(object :View.OnClickListener{
btn.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册