如何使用OnClickListener创建简单的事件//更改文本或颜色
//告诉我哪里出错了,我试图通过点击按钮来改变文本
val buttonMoto: Button = (findViewById<Button>(R.id.buttonMoto)) buttonMoto.setOnClickListener(View.OnClickListener { fun OnClick(view: View){ val textviewMoto: TextView = (findViewById<TextView>(R.id.textViewMoto)) textviewMoto.text = "Hello World"
如果你想创建onClick,这是非常简单的kotlin。
textview.onClick{ }
为什么不使用
if (view instanceof TextView) view.text = "Hello World";
甚至只是
view.text = "Hello world";
Jehad,如果你只是想改变一些按钮上的文字,只需像这样用lambda函数来使用它
findViewById<Button>(R.id.button).setOnClickListener { val textviewMoto = (findViewById<TextView>(R.id.textViewMoto)) textviewMoto.text = "Hello World" }
- Kotlin和Android TextWatcher具有CharSequence / String替换功能
- 如何在服务端获取数据的同时识别在android中下载的数据量
- 从1.0.2 – 1.0.3升级Kotlin:java.lang.NoSuchMethodError:没有虚方法provideInjectedData $ app_compileDebugKotlin()
- Android选择和取消选择适配器kotlin中的项目的问题?
- java.lang.NoClassDefFoundError:com.example.api.retrofit.AuthenticationInterceptor $ intercept $ 1
- 如何将Java类转换为Kotlin数据类
- 定时器崩溃KotlinNullPointerException内部片段
- 在Kotlin Android中处理多个函数中的可变变量
- 无法获取Meetup API访问令牌与改造 – Android