I have my fragments inside ViewPager
and I would like in one of them to have clickable RelativeLayout
. I am using data binding:
<data>
<variable
name="handlers"
type="com.matip.presenters.MyPresenter" />
</data>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> handlers.onLayoutClick()}">
...
...
...
</RelativeLayout>
My Fragments onCreateView:
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mBind = DataBindingUtil.inflate(inflater, R.layout.fragment_layout, container, false);
presenter = new MyPresenter();
mBind.includedLayout.setHandlers(presenter);
return mBind.getRoot();
}
But the onLayoutClick
is not being called. Does it have something to do with ViewPager? Does it take the click and not the fragment inside it? If so how can I fix that?
EDIT
My ViewPager Adapter:
private class MyViewPagerAdapter extends FragmentStatePagerAdapter {
public MyViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch(position) {
case 0:
return MainInfoFragment.newInstance(parkingId);
case 1:
return MainDescFragment.newInstance(parkingId);
case 2:
return MainServicesFragment.newInstance(parkingId);
default:
return null;
}
}
@Override
public int getCount(){
return 3;
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
switch(position){
case 0: return getContext().getString(R.string.info_title);
case 1: return getContext().getString(R.string.desc_title);
case 2: return getContext().getString(R.service_title);
default: return null;
}
}
}