Android 数据绑定-必须首先将Lambda表达式解析为其setter才能获取类型
我从数据绑定开始,但一旦我创建了onClick函数,我就无法运行该项目,这是我的布局 是我缺少的东西吗?@=用于,对于您应该使用的onClick@ @=用于,对于应使用的onClick@Android 数据绑定-必须首先将Lambda表达式解析为其setter才能获取类型,android,kotlin,mvvm,android-databinding,Android,Kotlin,Mvvm,Android Databinding,我从数据绑定开始,但一旦我创建了onClick函数,我就无法运行该项目,这是我的布局 是我缺少的东西吗?@=用于,对于您应该使用的onClick@ @=用于,对于应使用的onClick@ 你能给我解释一下双向数据绑定的区别吗?因为我正在跟踪一个只使用@{}而不是@={}的代码实验室,你能解释一下双向数据绑定之间的区别吗?因为我正在跟踪一个代码实验室,它只使用@{}而不是@={} <layout xmlns:android="http://schemas.android.com/apk/re
你能给我解释一下双向数据绑定的区别吗?因为我正在跟踪一个只使用@{}而不是@={}的代码实验室,你能解释一下双向数据绑定之间的区别吗?因为我正在跟踪一个代码实验室,它只使用@{}而不是@={}
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="userViewModel"
type="com.myproject.example.UserViewModel" />
</data>
....
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@={userViewModel.saveOrUpdateButton}"
android:onClick="@={() -> userViewModel.saveOrUpdate()}"
/>
dependencies {
def lifecycle_version = "2.2.0"
def room_version = "2.2.3"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
//coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
}
android:onClick="@{() -> userViewModel.saveOrUpdate()}"