android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.04k stars 3.01k forks source link

DataBinding has two important issues. #96

Closed KunMinX closed 4 years ago

KunMinX commented 4 years ago
  1. BindingAdapter do not support to any widget extends ViewGroup, such as DrawerLayout, TabLayout and so on.

  1. DataBinding Listener support is weird, for example: SeekBar.OnSeekBarChangeListener can bind app:onSeekBarChangeListener="@{click}" in layout well,while TabLayout.OnTabSelectedListener can not. app:onTabSelectedListener="@{click}" can not bind well.
KunMinX commented 4 years ago

for the first issue, you can reproduct it by this project: https://issuetracker.google.com/action/issues/143677219/attachments/27847098?download=true

for the second issue, the @{click} is like below:

public class ClickProxy implements TabLayout.OnTabSelectedListener{

        public void onLeftClick() {
            FragmentNavigator.getInstance().navigateUp();
        }

        @Override
        public void onTabSelected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    }

...

@Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, 
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_wish, container, false);
        mBinding = FragmentWishBinding.bind(view);
        mBinding.setClick(mClickProxy = new ClickProxy());
        return view;
    }

...

<data>

        <variable
            name="click"
            type="com.kunminx.fairytale.ui.page.about.WishFragment.ClickProxy" />

    </data>

...

           <com.google.android.material.tabs.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="40dp"
   --->        app:onTabSelectedListener="@{click}"
                app:tabBackground="@drawable/tab_item_selector"
                app:tabIndicatorHeight="0dp"
                app:tabRippleColor="@color/white"
                app:tabSelectedTextColor="@color/dark"
                app:tabTextAppearance="@style/TabLayoutTabTextStyle"
                app:tabTextColor="@color/dark">

Environment: AndroidX, Android Studio 3.5.3, gradle plugin 3.5.3, gradle version 5.4.1