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);
            }
        }
  • 相关阅读:
    UVA 11354
    HDU 4081 Qin Shi Huang's National Road System 最小/次小生成树的性质
    UVA 10269 Adventure of Super Mario floyd dp
    UVA 11280 Flying to Fredericton 最短路DP
    【专题】树状数组
    【专题】Subsequence
    共享python代码模块
    完全背包
    POJ 3253 Fence Repair
    POJ 3069 Saruman's Army
  • 原文地址:https://www.cnblogs.com/yejiurui/p/2837760.html
Copyright © 2011-2022 走看看