繁体   English   中英

取消adapter.notifyDataSetChanged

[英]Cancel adapter.notifyDataSetChanged

我对android有点陌生,我想知道是否有可能在运行notifyDataSetChanged()之后在中间取消它。

例如我的情况:

如果onResponse得到1作为响应,我会先得到PricePrice()然后得到getTransaction。

我将使用当前代码设置swipeRefreshListener:

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                            @Override
                            public void onRefresh() {
                                getTransactions(view);

                                Animation fadeIn = new AlphaAnimation(0, 1);
                                fadeIn.setInterpolator(new AccelerateInterpolator()); //and this
                                fadeIn.setDuration(1000);

                                swipeRefreshLayout.setRefreshing(true);

                                layoutBalance.setAnimation(fadeIn);
                                mActivities_RecyclerView.setAnimation(fadeIn);
                                swipeRefreshLayout.setRefreshing(false);

mActivities_RecyclerViewAdapter.notifyDataSetChanged();
                            }

                        });

我将回想起getTransaction,因为我需要从API中获取最新的数据。 但是,由于我使用改造队列的API调用将异步运行,因此在从服务器获取实际数据之前,我的数据将首先刷新。

因此,我的问题是可以取消notifyDataSetChanged()还是需要更改实现?

假设您有一个名为"APIData" ,现在您已经将其分配给了适配器和recyclerview,在发生Swipereferesh之后,您已经收到刷新的数据,该数据将再次位于一个名为"APIData"的数据模型中,现在让我们假设这是APIData2 ,现在使用

APIData.equals(APIData2)

这将检查以前的数据是否与新的数据相同,如果为真,则不需要执行notifyDataSetChanged()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM