Pass another view as parameter in data binding(在数据绑定中将另一个视图作为参数传递)
本文介绍了在数据绑定中将另一个视图作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的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())}'
这篇关于在数据绑定中将另一个视图作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:在数据绑定中将另一个视图作为参数传递


基础教程推荐
猜你喜欢
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01