- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
在 Twitter(官方应用)等 Android 应用中,当遇到 ListView 时,可以将其拉下(释放时会弹回)以刷新内容。
我想知道在您看来,实现它的最佳方式是什么?
我能想到的一些可能性:
有什么建议吗?
附:我想知道官方 Twitter 应用程序源代码什么时候发布。据说会发布,但是6个月过去了,从那以后我们就再也没听说过。
最佳答案
谷歌终于发布了正式版的pull-to-refresh库!
在支持库里面叫做SwipeRefreshLayout
,文档是here :
添加 SwipeRefreshLayout
作为 View 的父级,这将被视为刷新布局的拉动。 (我以ListView
为例,可以是LinearLayout
、ScrollView
等任何View
)
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pullToRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
为你的类添加一个监听器
protected void onCreate(Bundle savedInstanceState) {
final SwipeRefreshLayout pullToRefresh = findViewById(R.id.pullToRefresh);
pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshData(); // your code
pullToRefresh.setRefreshing(false);
}
});
}
您也可以根据需要调用pullToRefresh.setRefreshing(true/false);
。
更新
Android 支持库已被弃用,并已被 AndroidX 取代。可以找到新库的链接 here .
另外,您需要在您的项目中添加以下依赖项:
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
或
你可以去Refactor>>迁移到AndroidX,Android Studio会为你处理依赖。
关于android - 如何实现Android Pull-to-Refresh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4583484/
在我的phone-gap index.html javascript部分中,window.refresh用于IOS,this.refresh用于android。我想对两者使用相同的index.html
我正在使用 Guzzle 获取域上设置了元刷新的网页的 HTML: Guzzle 似乎没有拦截这种重定向。这是正确的吗?我可以将 Guzzle 配置为跟随刷新吗? 我应该考虑其他哪些解决方案来解决问
我试图在另一个 DropDownList 发生变化后刷新下拉列表,但是 Refresh() 方法是未定义错误正在提升。我再次尝试读取数据源,它显示它正在加载,但数据仍然相同。请帮助解决这个问题。 代码
swift 我正在努力做到这一点,当您在 tableview 上拉动刷新时,它会使用存储在 Parse.com 上的数据更新 tableview 我已经研究过了,看来我需要使用 loadObjects
我有以下物化 View - CREATE MATERIALIZED VIEW TESTRESULT ON PREBUILT TABLE WITH REDUCED PRECISION REFRESH F
我正在使用 Cognito 用户池对系统中的用户进行身份验证。成功的身份验证会提供ID token (JWT)、访问 token (JWT) 和刷新 token 。 documentation her
我想使用 FlashMessage 显示错误(或成功)消息同时让我的页面在所需时间重新加载 我正在使用 FlashMessage我的代码看起来像 render() { return ( {
更新:我已经写了一篇博文,介绍我对这个问题的了解。我仍然不完全理解它,但希望有人会阅读这篇文章并阐明我的问题:http://andymcfee.com/2012/04/04/icon-fonts-ps
所以我有一个物化 View (我知道......): CREATE MATERIALIZED VIEW vw_my_view_here REFRESH COMPLETE START WITH SYSD
我正在尝试使用 the angular-oauth2-oidc Silent Refresh实现与在 IdentityServer4 服务器中配置的隐式流相结合。我有一个在 ng new ng-and
TL;DR - 如果 oauth2 授权发生在原生 android/ios 应用程序中,我如何在后端刷新 token ? 我正在研究 oauth2 与谷歌日历的集成。我的堆栈是将 SPA 应用程序作为
作为前言,我对java很陌生。因此,请期待愚蠢的错误。 我正在尝试在 BlueJ 中使用 java 的绘图面板做一个项目,但我不知道如何制作一个具有移动对象的程序。这是一个项目,所以提供了代码。我们必
我正在尝试使用我在许多网站上找到的不显眼但非常有用的润色来润色我的网络编程技能。 Stackoverflow.com,举个例子。当我提出问题时,页面会提交问题,我的浏览器会自行重新加载并显示我的问题。
AjaxControlToolkit.dll.refresh 文件的作用是什么? 最佳答案 *.dll.refresh 文件是一个非常简单的文件,它告诉项目外部引用所在的位置。 http://mons
如何使用watir-webdrive刷新页面? 我尝试了他们在这里说的话:http://watirwebdriver.com/sending-special-keys/,但是没有运气。 browser
我目前正在制作一个交互式图表,该图表应该计算商业项目的潜在风险因素。为此,我一直在使用百度 ECharts,并让图表在视觉上工作,但是当数据发生变化时无法让图表更新。 数据来自外部调查问卷,该问卷使用
在 plupload div 之后,我有一个带有 plupload 的上传表单和一个带有 bool 值的复选框。 如果选中该复选框,我想更改 plupload 中 url 的值。 这是我的代码
我有一个相当大的PHP代码库(10k文件),可以在Windows计算机上使用Eclipse 3.4/PDT 2来工作,而这些文件则托管在Debian文件服务器上。我通过Windows上的映射驱动器进行
使用 Angularjs v0.9 和 php 来实现我的成员(member)系统 在下面的函数中,我将调用一个api来编辑成员(member)的数据,成功后,php函数将返回 {"success":
我正在使用 setColor 和 getColor 方法更改 JPanel 的颜色。 现在我想更改它,这样您就不必在调用 getColor 的函数中单击 getColor 按钮 100 毫秒。 但是在
我是一名优秀的程序员,十分优秀!