Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

Android 订单列表多个同名fragment里的刷新组件无法使用

以下编码,只有第一个fragment里的刷新组件能触发,其他四个都不行

RefreshLayout refreshLayout = getActivity().findViewById(R.id.refreshLayout);
DebugLogUtil.getInstance().Debug("测试 .." + refreshLayout.toString());
refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()));
refreshLayout.setRefreshFooter(new ClassicsFooter(getContext()));
refreshLayout.setEnableLoadMoreWhenContentNotFull(false);
refreshLayout.setOnRefreshListener(refreshlayout -> {
    page = 1;
    list = new ArrayList<>();
    req();
    refreshlayout.finishRefresh(1000/*,false*/);//传入false表示刷新失败
});
ticketFrag = new OrderFrag(0);
        ticketFrag1 = new Order1Frag(1);
        ticketFrag2 = new Order2Frag(2);
        ticketFrag3 = new Order3Frag(3);
        ticketFrag4 = new Order4Frag(4);
        fragmentList.add(ticketFrag);
        fragmentList.add(ticketFrag1);
        fragmentList.add(ticketFrag2);
        fragmentList.add(ticketFrag3);
        fragmentList.add(ticketFrag4);
//        mPagerAdapter.addFragment(ticketFrag);
//        mPagerAdapter.addFragment(ticketFrag1);
//        mPagerAdapter.addFragment(ticketFrag2);
//        mPagerAdapter.addFragment(ticketFrag3);
//        mPagerAdapter.addFragment(ticketFrag4);
 String[] title = {"全部", "待付款", "待发货", "待收货", "待评价"};
        adapter = new MyPagerAdapter(getSupportFragmentManager(), fragmentList, title);
        viewPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(viewPager);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我自己的方案是Fragment不新建,仍然用同名的 ,用多个不同名但是内容相同的layout,去区分开不同的刷新组件的id,问题解决,但是我是想通过在fragment内部下功夫解决,有无大佬指示


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...