在数据绑定中将另一个视图作为参数传递 [英] Pass another view as parameter in data binding

查看:0
本文介绍了在数据绑定中将另一个视图作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的XML的另一个视图作为Google数据绑定中方法的参数传递...如下所示:

<LinearLayout
    android:id="@+id/faq_subject_about_ego"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/border_faq_btn"
    android:orientation="horizontal"
    android:layout_marginBottom="20dp"
    android:padding="4dp"
    android:gravity="center"
    android:onClick='@{(faq_title_about) -> viewModel.subjectRequest(faq_title_about.getText())}'>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon_faq"
        android:layout_marginRight="8dp"
        android:clickable="false" />

    <ebanx.com.ego.utils.custom_extension.CustomButtonBold
        android:id="@+id/faq_title_about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Button_FAQ"
        android:text="@string/btn_about_ego"
        android:clickable="false" />
</LinearLayout>
我需要CustomButtonBold中的文本...但这行不通。

如何将按钮文本作为参数传递?

如有任何帮助,我们将不胜感激!

推荐答案

为id-able生成的成员具有CamelCase名称格式。此外,提供给OnClickListener的视图是被单击的视图。因此,只需任意命名参数并使用正确的"全局"成员即可。

android:onClick='@{(v) -> viewModel.subjectRequest(faqTitleAbout.getText())}'

这篇关于在数据绑定中将另一个视图作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆