gpt4 book ai didi

java - SwipeRefreshLayout 动画卡住 onRefresh()

转载 作者:太空狗 更新时间:2023-10-29 14:05:12 26 4
gpt4 key购买 nike

当我滑动刷新时,SwipeRefreshLayout 的动画显示,但在 onRefresh() 运行时它被卡住,并且只有在 onRefresh() 完成时才开始旋转。

主要 Activity

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myFAB = (FloatingActionButton) findViewById(R.id.myFAB);
recyclerView = (RecyclerView) findViewById(R.id.rv);
recyclerView.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm);
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(this));
callCadastroEncoemnda();
callPackageList();
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.setColorSchemeResources(
android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}

刷新时:

@Override
public void onRefresh() {
swipeRefreshLayout.setRefreshing(true);
Update.updateAll(MainActivity.this);
//Check if the data change
if (!packages.equals(dao.getPackages())) {
adapter.updateList(dao.getPackages());
}
swipeRefreshLayout.setRefreshing(false);
}

最佳答案

已解决!

我已将刷新代码放在 Runnable 上:(我也改变了我的刷新)

@Override
public void onRefresh() {
new Thread(new Runnable() {
@Override
public void run() {
try {
if (Update.updateAll(MainActivity.this)) {
packages = dao.getPackages(config.getFilter());
packagesAux = dao.getPackages(config.getFilter());
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.animateTo(packages);
}
});
}
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
});
}
}).start();
}

关于java - SwipeRefreshLayout 动画卡住 onRefresh(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32929982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com