在数据绑定中将另一个视图作为参数传递视图、绑定、中将、参数

2023-09-03 14:39:57 作者:樱桃炖小丸子i

我正在尝试将我的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中的文本...但这行不通。

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

SpringMVC数据绑定使用篇 1

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

推荐答案

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

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