zoukankan      html  css  js  c++  java
  • Android异步查询框架AsyncQueryHandler使用简介

    1.首先是写一个查询的方法

    //查询数据
        private void startQuery() {
            Uri uri=Sms.CONTENT_URI;
            String selection=" thread_id=?";
            String[] selectionArgs=new String[]{thread_id};
            //查询
            //projection 查询的字段
            queryHandler.startQuery(0, null, uri, SMS_PROJECTION, selection, selectionArgs, " date DESC");
        }

    2.把需要查询的字段给抽取出来。

    /**
         * 将查询所用的字段处理出来
         */
        private static final String[] SMS_PROJECTION=new String[]{
            "_id",
            "address",
            "date",
            "type",
            "body",
        };
        /**
         * 当前字段所对应的位置
         */
        private static final int ID_COLUMN_INDEX = 0;
        private static final int ADDRESS_COLUMN_INDEX = 1;
        private static final int DATE_COLUMN_INDEX = 2;
        private static final int TYPE_COLUMN_INDEX = 3;
        private static final int BODY_COLUMN_INDEX = 4;

    3.然后继承异步查询框架

    private class QueryHandler extends AsyncQueryHandler{
    
            public QueryHandler(ContentResolver cr) {
                super(cr);
            
            }
            
            //查询执行完成后悔执行这个方法
            protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
                // TODO Auto-generated method stub
                super.onQueryComplete(token, cookie, cursor);
                //界面更新
                adapter.changeCursor(cursor);
            }
        }
  • 相关阅读:
    Win7系统下搭建Tomcat服务器
    转:在线框架引用 bootstrap/jq/jqmobile/css框架
    转:Web.config配置文件详解
    转:HTML和Web窗体的区别
    在VS2010中创建网站并发布
    nohup 借助cronolog进行日志分割 Linux
    Linux (centos 8) 安装nginx1.20
    Ubuntu 安装使用yum--转载
    C# 字符串插值内部工作原理
    Linux 安装MySQL
  • 原文地址:https://www.cnblogs.com/yejiurui/p/2837760.html
Copyright © 2011-2022 走看看