[英]error in event handing in data binding android
I am getting the error: 我收到错误消息:
****/ data binding error ****msg:Cannot find method handler on ViewDataBinding app/src/main/res/layout/activity_main.xml loc:55:27 - 55:76 ****\ data binding error ****
<data class="ActivityMainBinding">
<variable
name="login"
type="***.loginViewModel" />
<variable
name="handler"
type="***.LoginHandler" />
</data>
<Button
android:onClick="@{() -> handler(context).onLoginButtonClicked(login)}"
android:id="@+id/submit_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:text="Sign In"
app:layout_constraintEnd_toEndOf="@+id/user_password"
app:layout_constraintStart_toStartOf="@+id/user_password"
app:layout_constraintTop_toBottomOf="@+id/user_password"/>
ANd the login handler class: 和登录处理程序类:
class LoginHandler(mContext: Context) {
var mContext=mContext as Activity
fun onLoginButtonClicked(userInfo: loginViewModel){
Log.i("Email is ",userInfo.userEmailAddress)
Log.i("Password is ",userInfo.userPassword)
userInfo.login(userInfo.userEmailAddress, userInfo.userPassword, mContext)
}
}
Why am I getting this error? 为什么会出现此错误? I am rechecked the function name and syntax on click.
单击时会重新检查函数名称和语法。
Solution tried: 1. Clean and rebuild the project. 尝试解决的方法:1.清理并重建项目。
handler
is defined as a variable, so handler(context)
makes no sense. handler
被定义为变量,因此handler(context)
没有任何意义。
You will need to just use handler
and initialize the object in your code. 您将只需要使用
handler
并在代码中初始化对象。
handler.onLoginButtonClicked(login)
I'm not familiarized with data binding, but I read you should declare import on top of your layout. 我对数据绑定不熟悉,但是我读到您应该在布局顶部声明导入 。
<data>
<import type="***.LoginHandler"/>
</data>
Info: https://developer.android.com/topic/libraries/data-binding/index.html#layout_details 信息: https : //developer.android.com/topic/libraries/data-binding/index.html#layout_details
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.