gpt4 book ai didi

java - SwipeRefreshLayout 只显示一项?

转载 作者:行者123 更新时间:2023-12-01 12:41:20 25 4
gpt4 key购买 nike

我尝试为现有的 ListView 实现 SwipeRefreshLayout,但每当我运行该程序时,即使我通过拉动刷新它,它也只显示一项。但是,刷新动画有效。相关代码如下:

    items = (ListView)findViewById(R.id.myList);
adapter = new Adapter(ctx);
adapter.setTextKey("myItem");
//adapter.setImageKey("image");
items.setAdapter(adapter);
adapter.loadObjects();

final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe2);
swipeView.setEnabled(false);
swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeView.setRefreshing(true);
( new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
swipeView.setRefreshing(false);

}
}, 3000);
}
});

items.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {

}

@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
boolean enable = false;
if(items != null && items.getChildCount() > 0){
// check if the first item of the list is visible
boolean firstItemVisible = items.getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = items.getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
swipeView.setEnabled(enable);
}
});

最佳答案

问题不在于 SwipeRefreshLayout。我在xml中将ListView放在ScrollView中,导致错误。

关于java - SwipeRefreshLayout 只显示一项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25072547/

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