Change Switch state without animation

前端 未结 7 1949
醉酒成梦
醉酒成梦 2020-12-09 07:54

In my Android project, I have a ListView with rows containing SwitchCompat items (AppCompat for Switch widget).

My problem occ

7条回答
  •  盖世英雄少女心
    2020-12-09 08:30

    Using SwitchCompat and DataBinding

    @BindingAdapter({"bind:checkedState"})
    public static void setCheckedState(SwitchCompat switchView, boolean checked) {
        int visibility = switchView.getVisibility();
        switchView.setVisibility(View.INVISIBLE);
        switchView.setChecked(checked);
        switchView.setVisibility(visibility);
    }
    

    Then in xml:

    
    

    And don't forget to call executePendingBindings() (thanks AAverin)

提交回复
热议问题