从Fragment中禁用MainActivity SwipeRefreshLayout

时间:2017-09-20 08:26:59

标签: android android-studio android-fragments expandablelistview swiperefreshlayout

我有一个包含SwipeRefreshLayout的主要活动。该活动包含fragments

我想从特定片段中禁用SwipeRefreshLayout,因为SwipeRefreshLayout的滑动手势会干扰片段上ExpandableListView的滚动手势。

为此,我尝试了以下内容,但没有成功:

片段上的

我有:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.listfragment, container, false);

    //......
    expListView  = (ExpandableListView) v.findViewById(R.id.expandableList);
    final MainActivity mainAct = (MainActivity) getActivity();
    //.......
    expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            Log.d("test","Disabled");
            //SwipeRefreshLayout is called swipeRefreshLayout on MainActivity
            mainAct.swipeRefreshLayout.setEnabled(false);

        }
    });

运行此功能后,我可以看到日志消息,因此swipeRefreshLayout应设置为 false ,但SwipeRefreshLayout的下拉手势正常工作

1 个答案:

答案 0 :(得分:2)

试试:

从你的片段(演员):

((MainActivity) getActivity()).disableSwipe();

现在进入您的活动:

private void disableSwipe(){
    swipeRefreshLayout.setEnabled(false);
}

检查this answer了解详情