gpt4 book ai didi

android - 滑动刷新仅在用户滑动时调用,而不是在用户到达列表顶部时调用

转载 作者:搜寻专家 更新时间:2023-11-01 09:38:39 24 4
gpt4 key购买 nike

https://github.com/googlesamples/android-SwipeRefreshLayoutBasic

引用上面的示例。当用户向上滚动到达列表顶部时,将调用滑动刷新。我想要的是仅当用户专门为其滑动时才调用滑动刷新。当用户向上滚动并到达顶端时不调用滑动刷新。

当我使用下面的库时,我得到了我想要的。但是我在使用这个库时遇到了一些问题,所以我不想使用它。github.com/baoyongzhang/android-PullRefreshLayout

这是我不想要的视频剪辑: https://drive.google.com/file/d/0By2g3SV1qz5TUFdZZ1FUNmxzU1E/view?usp=sharing

最佳答案

现在从xml开始

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/contact_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/contact_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</android.support.v4.widget.SwipeRefreshLayout>

在上面的代码中,swipeRefreshLayout 中有一个 listview,将其放在您的 Activity 布局中

然后在你的 Activity 中通过这个在 Activity 类中声明它

SwipeRefreshLayout swipeRefreshLayout;
ListView listView;

然后在 onCreate 方法内部将 xml 代码分配给它

     swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.contact_swipe_refresh);
listView = (ListView) findViewById(R.id.contact_listView);

然后把你的adapter放到listview上,然后设置onrefreshlistener到swiperefreshlayout

swipeRefreshLayout.setOnRefreshListener(new 

SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//call a method here which make a webservice call or what ever you are using to put data inside the listview then set adapter and call

swipeRefreshLayout.setRefreshing(false);
}
}
});

关于android - 滑动刷新仅在用户滑动时调用,而不是在用户到达列表顶部时调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41296030/

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