android - 数据绑定(bind)传递带有特殊字符的 xml 元素

标签 android data-binding android-databinding android-binding-adapter

考虑下面的 bindingAdapter

@BindingAdapter({"pager"})
public static void bindViewPagerTabs(final TabLayout view, final ViewPager pagerView)
{
    view.setupWithViewPager(pagerView, true);
}

xml中的设置是:

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/card_control_tab_layout"
            style="@style/tab_in_toolbar_style"
            android:background="@color/colorPrimary"
            app:tabGravity="fill"
            app:pager="@{(pager_r)}"
            app:tabMode="scrollable" />

出现以下错误:

error: cannot find symbol class ActivityCardControlBindingImpl

但是,如果我将寻呼机 ID 更改为没有下划线或任何特殊字符(如 @+id/pager)的任何内容,它就可以正常工作,有什么正当理由吗?

最佳答案

如果您编写 app:pager="@{(pagerR)}" 而不是 app:pager="@{(pager_r)}",它会起作用。你也不需要括号,所以你可以只写 app:pager="@{pagerR}"

编辑:

But if I changed the pager Id to anything without the underscore or any special characters like @+id/pager it works perfectly, any valid reason ?

我不知道其他特殊字符,但是当您在 View ID 中使用下划线时,像“pager_r”这样的蛇形 View ID 会通过数据绑定(bind)转换为驼峰变量,如“pagerR”。因此,正如我最初的回答所述,如果您使用 @+id/pager_r,则可以使用变量 pagerR。

关于android - 数据绑定(bind)传递带有特殊字符的 xml 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53853280/

相关文章:

android - 如何在 'back' 窗口上叠加 'next' 和 "pick wifi network "按钮?

wpf - 数据触发器绑定(bind)未按预期工作

c# - 混淆包含数据绑定(bind)到内部类属性的程序集

安卓数据绑定(bind) : Is there a good way to show/hide an includes tag?

android - android数据绑定(bind)的问题

android - 应用程序卸载时无法获取接收器

java - Android 中的 AsyncTask 循环

验证已触发,但 Silverlight 4 中的用户控件未出现红色边框

Android BindingAdapter 的执行顺序?

android - AppWidgetHost 在主线程上创建 View