gpt4 book ai didi

java - SwipeRefreshLayout 刷新监听器不调用 onRefresh()

转载 作者:行者123 更新时间:2023-11-29 19:19:33 26 4
gpt4 key购买 nike

我目前有一个 SwipeRefreshLayout,它在我下拉时不会调用它的 OnRefresh 方法。我的代码有问题吗?

public class MainActivity extends AppCompatActivity {
private SwipeRefreshLayout swipe_view;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

swipe_view = (SwipeRefreshLayout) findViewById(R.id.this_will_work);

swipe_view.setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
Toast.makeText(getApplicationContext(), "OnRefresh() test", Toast.LENGTH_SHORT).show();
}
});

最佳答案

你应该有一个服务或将像下面这样更新的东西:

private void refresh() {
startService(new Intent(this, UpdaterService.class));
}

然后刷新:

mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout.setOnRefreshListener(this);
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
refresh();
}});

//here refreshed Item
//getLoaderManager().initLoader(0, null, this);

if (savedInstanceState == null) {
refresh();
}

和您的 onRefresh() 应该包含相同的方法 refresh()

关于java - SwipeRefreshLayout 刷新监听器不调用 onRefresh(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42744587/

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