java - SwipeRefreshLayout 阻止 android.widget.switch 拖动

标签 java android android-studio switch-statement swiperefreshlayout

我有一个 Activity 和 10 个根据 Activity 绘制的 fragment 。 Activity 上的所有 fragment 都需要“拖动刷新”。我添加了“滑动刷新布局”来创建它。现在,当我点击开关时,一切都很好;但是当我尝试将其从一个阶段拖动到另一个阶段时,会出现滑动刷新,并且开关只是停留在相同的位置。那么如何才能在用户将开关从一个位置拖动到另一个位置时及时阻止滑动刷新布局的刷新呢?

我试着把它做成这样:

    onOffSwitchSettings.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            ((MainActivity) getActivity()).swipeContainer.setRefreshing(false);
            return false;
        }
    });

但是之后我怎样才能打开它呢?

最佳答案

根据SwipeRefreshLayout引用:

The SwipeRefreshLayout will notify the listener each and every time the gesture is completed again; the listener is responsible for correctly determining when to actually initiate a refresh of its content. If the listener determines there should not be a refresh, it must call setRefreshing(false) to cancel any visual indication of a refresh. If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.

您忘记使用 ((MainActivity)getActivity()).swipeContainer.setEnabled(fals‌​e) 方法。

另一个问题是,使用上面的方法您将永久禁用SRL,因此您需要在操作正确时再次启用它,我的意思是不再有拖动。

希望对你有帮助

关于java - SwipeRefreshLayout 阻止 android.widget.switch 拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156495/

相关文章:

java - 我可以为某些 Actor 的自动名称添加前缀吗?

java for循环运行list只执行一次

java - SSL 有两种方式不适用于我的 OpenLDAP

android - Xamarin.Forms 使用相机拍照显示方向错误并在后退按钮上崩溃

android - unity visual studio android 调试器通过 USB

Java: string.replaceAll() 不工作

android - 什么被视为 "decoupled project"(Gradle)?

Android Studio 0.4.3 - 在根项目中找不到任务 'assemble'

android - .gradle 文件夹在 android studio 更新后是红色的,如何解决?

android-studio - Android Studio lldb 和 GDB 之间切换