Android Databinding: “Method references using '.' is deprecated”

前端 未结 4 2190
悲哀的现实
悲哀的现实 2021-02-19 07:34

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

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

4条回答
  •  旧巷少年郎
    2021-02-19 08:00

    You can still use JavaVersion.VERSION_1_8. Just use app:onClick, and define a BindingAdapter like this:

    @BindingAdapter("onClick") 
    public static void bindOnClick(View view, final Runnable runnable) {
        view.setOnClickListener(v -> runnable.run());
    }
    

    Then you can use app:onClick="@{handler::onItemClick}" without warnings or errors.

提交回复
热议问题