Reputation: 830
Consider the following bindingAdapter
@BindingAdapter({"pager"})
public static void bindViewPagerTabs(final TabLayout view, final ViewPager pagerView)
{
view.setupWithViewPager(pagerView, true);
}
and the setting in the xml is :
<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" />
Gives the following error :
error: cannot find symbol class ActivityCardControlBindingImpl
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 ?
Upvotes: 0
Views: 321
Reputation: 830
I found the same answer as Janosch Pelzer's with a litte more explsnation here
Cannot refer to other View ID in Android data binding
Upvotes: 0
Reputation:
It works if you write app:pager="@{(pagerR)}"
instead of app:pager="@{(pager_r)}"
. Also you don't need the brackets, so you could just write app:pager="@{pagerR}"
.
EDIT:
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 ?
I don't know about other special characters, but when you use the underscore in your view ids the snake case view ids like "pager_r" get converted by databinding to camel came variables like "pagerR". So as my original answer states, if you use @+id/pager_r you can use the variable pagerR.
Upvotes: 1