在对SQLite数据库操作后,ListView显示的数据却无法及时刷新,可以使用SwipeRefreshLayout实现下拉刷新,更新ListView。
将ListView放在SwipeRefreshLayout类中

   .support.v4.widget.SwipeRefreshLayout        android:id="@+id/swipe_refresh"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:layout_behavior="@string/appbar_scrolling_view_behavior" >        "@+id/list_view"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:fitsSystemWindows="true"/>    .support.v4.widget.SwipeRefreshLayout>

在代码中实现具体的刷新逻辑

swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);        swipeRefresh.setColorSchemeResources(R.color.colorPrimary);//设置下拉刷新进度条的颜色        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { //设置下拉刷新的监听器            @Override            public void onRefresh() {                new Thread(new Runnable() {                    @Override                    public void run() {                        try{                            Thread.sleep(1000);                        }catch (InterruptedException e){}                        runOnUiThread(new Runnable() {                            @Override                            public void run() {                                mlist.clear();                                initMemoData();                                memoAdapter.notifyDataSetChanged();                                swipeRefresh.setRefreshing(false);                            }                        });                    }                }).start();            }        });

更多相关文章

  1. Android动画分类
  2. Android(安卓)Dialog弹出时背景全透明
  3. android studio不能运行
  4. Android(安卓)Material Design TabLayout属性app:tabMode和app:
  5. android WebView html网页设置长按的时候不出现复制粘贴
  6. Android多媒体分析(六)对AudioManager的一点补充
  7. android设置定时关闭的dialog
  8. Android(安卓)Tab类型主界面总结
  9. android ListView向上滑动隐藏标题,下拉显示标题栏

随机推荐

  1. Android 的第一个游戏
  2. android 文本框(textview)左右滑动
  3. Android之permission权限列表
  4. Android 如何简单的实现【轮播图 】— Vi
  5. Android 关于listview
  6. android Json数据构建于解析
  7. Android 代码中如何将dp,sp转成px
  8. 火爆新东西,仿QQ版本的ResideMenuItem框架
  9. Android java.lang.NoSuchMethodError
  10. Android在listview添加checkbox实现原理