please+define+android_sdk_roots,Android Databinding: “Method references using '

博主在使用安卓数据绑定时遇到了编译警告,提示方法引用使用'.'已被弃用,建议使用'handler::onItemClick'。然而在条件语句中应用双冒号操作符导致错误。尝试反转条件表达式并未解决问题。讨论了如何正确处理这种情况下方法引用的语法。
摘要由CSDN通过智能技术生成

When using databinding in my app, I get the following warning when compiling:

Warning:Method references using '.' is deprecated. Instead of 'handler.onItemClick', use 'handler::onItemClick'

Please see my XML below.

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:onClick="@{!active ? handler.onItemClick : null}"

android:background="@color/backgroundWhite"/>

Please note the : from the conditional statement

Pretty straightforward message, until I change the '.' to '::'.

android:onClick="@{!active ? handler::onItemClick : null}"

Since the onItemClick is inside a conditional statement, it seems to interpret the first of the two ::'s as the 'else' statement of the condition. On the second ':', I get the error:

expected, got ':'

EDIT: As @CommonsWare suggested in the comments, inverting the statement to

"@{active ? null : handler::onItemClick}"

doesn't help either, a similar error is shown (see comments)

EDIT2: Apparently, when stripping the conditional statement away, being left with "@{handler::onItemClick}", it still gives an error: '!=', '%', '*', '+', ',', '-', '.', '/', ', '>=', '>>', '>>>' or '[' expected, got ':' Using the dot-notation, still gives a warning when compiling

Is there any way to escape these ::'s, so it is interpreted correctly?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值