コトリンで:
ここでは、別のビューのパラメーター onClick としてビューを渡しています
次のように、最初に xml レイアウトでHandlerクラス オブジェクトを定義します。
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable
name="handler"
type="com.demoapp.controllers.Handler" />
</data>
クリック機能を実行するボタンを定義します。
<Button
android:id="@+id/button2"
android:onClick="@{(view) -> handler.getbuttonClickEvent(textViewId)}"
.../>
そして、あなたのテキストビューは次のようになります: TextView idはtextViewIdのように変換されることを覚えておいてください
<TextView
android:id="@+id/text_view_id"
... />
Handler クラスの最終セットアップ メソッド
fun getbuttonClickEvent(view: TextView){
view.text="Hello World"
}