Android中更改SQLite数据库中的数据后,刷新ListView。

来源:互联网 发布:天气预报哪个软件好 编辑:程序博客网 时间:2024/05/18 03:06

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

   <android.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" >        <ListView            android:id="@+id/list_view"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:fitsSystemWindows="true"/>    </android.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();            }        });
阅读全文
0 0
原创粉丝点击