从片段中禁用MainActivity SwipeRefreshLayout
我有一个主要活动,其中包括一个SwipeRefreshLayout
。该活动包含fragments
。从片段中禁用MainActivity SwipeRefreshLayout
我想从特定片段中禁用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
应设置到假,但是对于SwipeRefreshLayout下拉手势工作
刚刚尝试,如:
从你的片段(铸造):
((MainActivity) getActivity()).disableSwipe();
现在,在您的活动:
private void disableSwipe(){
swipeRefreshLayout.setEnabled(false);
}
检查this answer更多细节
好吧,我会努力,谢谢。 – codeKiller
这应该有效,但我宁愿使用[委托](https://developer.android.com/training/basics/fragments/communicating.html) –
@LucaNicoletti的方式,我假设代表团的意思是使用界面?为什么界面会比这个解决方案更好?这个界面看起来很简单,只需要很少的代码。 – codeKiller
安置自己的活动代码以及 –