android - SwipeRefreshLayout 刷新动画不会停止,尽管我设置了 swipeView.setRefreshing(false)
问题描述
我找到了一些答案,例如
加上其他一些问答,但直到现在我还没有找到我的解决方案,即使我也无法理解这个问题。
实际上这个类是 pageAdapter
我的代码是
@Override
public Object instantiateItem(ViewGroup container, int position) {
View listView = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_common_list, container, false);
swipeView = (SwipeRefreshLayout) listView.findViewById(R.id.nfs);
swipeView.setColorSchemeResources(R.color.colorPrimary,
R.color.colorAccent,
R.color.yes,
R.color.no);
swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
(new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
Log.d("SwipeView","Refrehing");
swipeView.setRefreshing(false);
Log.d("SwipeView ",swipeView.isRefreshing()+"");
}
}, 3000);
}
});
}
我的fragment_common_list视图是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/nfs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/tab_height">
<ListView
android:id="@+id/commonList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
解决方案
解决方案:
代替:
swipeView = (SwipeRefreshLayout) listView.findViewById(R.id.nfs);
写:
swipeView = (SwipeRefreshLayout) findViewById(R.id.nfs);
如果是Activity
, 声明它onCreate();
如果它在 中,则使用视图对象Fragment
声明它。onCreateView()
试试看,希望对你有帮助。
推荐阅读
- excel - Microsoft Access 例程生成的 Excel 报告出现错误 1004:方法打开对象工作簿失败
- shell - 无法将 sed 的输出分配给变量
- database - 如何计算数据库中所有原始数据在laravel中剩余的天数
- javascript - 如何在nodejs中结合同步和异步功能
- java - DateTimeFormatter 在格式化后添加一年至今
- javascript - 获取在 Angular 7 fullcalendar 中单击的事件日期
- ssas - 为什么Dimension和Cube的存储方式可以不同?
- react-native - 尝试运行 react-native run-android 时,JS bundler 立即关闭
- c++ - 在函数内部初始化 unsigned char 指针返回空指针
- plotly - Plotly.js - 删除跟踪显示错误