WEB开发网
开发学院手机开发Android 开发 Loader和Fragment使用示例代码 阅读

Loader和Fragment使用示例代码

 2011-03-19 11:57:23 来源:本站整理   
核心提示: static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS, Contacts.CONTACT_PRESENCE

   static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
       Contacts._ID,
       Contacts.DISPLAY_NAME,
       Contacts.CONTACT_STATUS,
       Contacts.CONTACT_PRESENCE,
       Contacts.PHOTO_ID,
       Contacts.LOOKUP_KEY,
     };

   public Loader<Cursor> onCreateLoader(int id, Bundle args) { //这里的处理是异步的
       Uri baseUri;
       if (mCurFilter != null) {
         baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI,
             Uri.encode(mCurFilter));
       } else {
         baseUri = Contacts.CONTENT_URI;
       }

     String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
           + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
           + Contacts.DISPLAY_NAME + " != '' ))";
       return new CursorLoader(getActivity(), baseUri,
           CONTACTS_SUMMARY_PROJECTION, select, null,
           Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
     }

   public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
       mAdapter.swapCursor(data); //处理完成
     }

   public void onLoaderReset(Loader<Cursor> loader) {
       mAdapter.swapCursor(null);
     }
   }
}

上一页  1 2 

Tags:Loader Fragment 使用

编辑录入:coldstar [复制链接] [打 印]
赞助商链接