最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用CursorLoader異步加載數(shù)據(jù)

 更新時間:2018年07月05日 14:25:13   作者:zzqlivecn  
這篇文章主要為大家詳細(xì)介紹了使用CursorLoader異步加載數(shù)據(jù),具有一定的參考價值,感興趣的小伙伴們可以參考一下

Android 3.0引入了CursorLoader實現(xiàn)異步加載數(shù)據(jù),為了避免同步查詢數(shù)據(jù)庫時阻塞UI線程的問題。在API 11之前可以通過下載支持庫,來使之前的系統(tǒng)支持此功能。

下面是一個例子:

public class ListViewLoader extends ListActivity
  implements LoaderManager.LoaderCallbacks<Cursor> {

 // This is the Adapter being used to display the list's data
 SimpleCursorAdapter mAdapter;

 // These are the Contacts rows that we will retrieve
 static final String[] PROJECTION = new String[] {ContactsContract.Data._ID,
   ContactsContract.Data.DISPLAY_NAME};

 // This is the select criteria
 static final String SELECTION = "((" + 
   ContactsContract.Data.DISPLAY_NAME + " NOTNULL) AND (" +
   ContactsContract.Data.DISPLAY_NAME + " != '' ))";

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // Create a progress bar to display while the list loads
  ProgressBar progressBar = new ProgressBar(this);
  progressBar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT, Gravity.CENTER));
  progressBar.setIndeterminate(true);
  getListView().setEmptyView(progressBar);

  // Must add the progress bar to the root of the layout
  ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
  root.addView(progressBar);

  // For the cursor adapter, specify which columns go into which views
  String[] fromColumns = {ContactsContract.Data.DISPLAY_NAME};
  int[] toViews = {android.R.id.text1}; // The TextView in simple_list_item_1

  // Create an empty adapter we will use to display the loaded data.
  // We pass null for the cursor, then update it in onLoadFinished()
  mAdapter = new SimpleCursorAdapter(this, 
    android.R.layout.simple_list_item_1, null,
    fromColumns, toViews, 0);
  setListAdapter(mAdapter);

  // Prepare the loader. Either re-connect with an existing one,
  // or start a new one.
  getLoaderManager().initLoader(0, null, this);
 }

 // Called when a new Loader needs to be created
 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
  // Now create and return a CursorLoader that will take care of
  // creating a Cursor for the data being displayed.
  return new CursorLoader(this, ContactsContract.Data.CONTENT_URI,
    PROJECTION, SELECTION, null, null);
 }

 // Called when a previously created loader has finished loading
 public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
  // Swap the new cursor in. (The framework will take care of closing the
  // old cursor once we return.)
  mAdapter.swapCursor(data);
 }

 // Called when a previously created loader is reset, making the data unavailable
 public void onLoaderReset(Loader<Cursor> loader) {
  // This is called when the last Cursor provided to onLoadFinished()
  // above is about to be closed. We need to make sure we are no
  // longer using it.
  mAdapter.swapCursor(null);
 }

 @Override 
 public void onListItemClick(ListView l, View v, int position, long id) {
  // Do something when a list item is clicked
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實現(xiàn)從網(wǎng)絡(luò)獲取圖片顯示并保存到SD卡的方法

    Android實現(xiàn)從網(wǎng)絡(luò)獲取圖片顯示并保存到SD卡的方法

    這篇文章主要介紹了Android實現(xiàn)從網(wǎng)絡(luò)獲取圖片顯示并保存到SD卡的方法,涉及Android操作多媒體文件及系統(tǒng)硬件設(shè)備的相關(guān)技巧,需要的朋友可以參考下
    2015-12-12
  • Android AnalogClock簡單使用方法實例

    Android AnalogClock簡單使用方法實例

    這篇文章主要介紹了Android AnalogClock簡單使用方法,結(jié)合實例形式簡單分析了AnalogClock的布局調(diào)用技巧,需要的朋友可以參考下
    2016-01-01
  • Android 中糟糕的AsyncTask

    Android 中糟糕的AsyncTask

    本文主要介紹Android 中的AsyncTask,這里整理了AsyncTsak 異步處理數(shù)據(jù)的知識,并且講到引起的問題和替代方案,有興趣的小伙伴可以參考下
    2016-08-08
  • Android串口通信apk源碼詳解(附完整源碼)

    Android串口通信apk源碼詳解(附完整源碼)

    這篇文章主要介紹了Android串口通信apk源碼詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • 怎么發(fā)布打包并發(fā)布自己的Android應(yīng)用(APP)

    怎么發(fā)布打包并發(fā)布自己的Android應(yīng)用(APP)

    前面我為大家講的都是關(guān)于Android開發(fā)方面的知識點和技術(shù),不少朋友可能會感到疑惑--究竟我該怎么打包、發(fā)布自己開發(fā)的APP,怎樣將我的APP放到網(wǎng)上工別人下載,怎樣保證我的APP安全及版權(quán)問題呢
    2013-11-11
  • Android實現(xiàn)直接播放麥克風(fēng)采集到的聲音

    Android實現(xiàn)直接播放麥克風(fēng)采集到的聲音

    這篇文章主要介紹了Android實現(xiàn)直接播放麥克風(fēng)采集到的聲音,涉及Android音頻操作的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • Android  ListView 條目多樣式展示實例詳解

    Android ListView 條目多樣式展示實例詳解

    這篇文章主要介紹了Android ListView 條目多樣式展示的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • Android桌面組件App Widget完整案例

    Android桌面組件App Widget完整案例

    這篇文章主要介紹了Android桌面組件App Widget完整案例,較為詳細(xì)的分析了Android桌面組件App Widget的功能、定義及實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • Android編程中FileOutputStream與openFileOutput()的區(qū)別分析

    Android編程中FileOutputStream與openFileOutput()的區(qū)別分析

    這篇文章主要介紹了Android編程中FileOutputStream與openFileOutput()的區(qū)別,結(jié)合實例形式分析了FileOutputStream與openFileOutput()的功能,使用技巧與用法區(qū)別,需要的朋友可以參考下
    2016-02-02
  • Android使用WebView播放flash的方法

    Android使用WebView播放flash的方法

    這篇文章主要介紹了Android使用WebView播放flash及判斷是否安裝flash插件的方法,以實例形式詳細(xì)講述了從布局、邏輯判斷到功能最終實現(xiàn)播放Flash的方法,是Android程序設(shè)計中比較典型的應(yīng)用,需要的朋友可以參考下
    2014-11-11

最新評論

海晏县| 瓦房店市| 大渡口区| 乐安县| 乌恰县| 景宁| 托克托县| 衡东县| 黄大仙区| 津市市| 宁明县| 永川市| 白银市| 抚远县| 安阳县| 沁源县| 伊春市| 黑水县| 南涧| 轮台县| 沿河| 井研县| 冀州市| 迁西县| 灌南县| 青川县| 桑日县| 卢龙县| 镇安县| 杭锦后旗| 新乡市| 精河县| 浪卡子县| 宁陵县| 马山县| 白水县| 钟祥市| 额济纳旗| 荔波县| 巴东县| 河北区|