国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Android - 使用CursorLoader異步加載數(shù)據(jù)

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

2022-03-09 15:37zzqlivecn Android

這篇文章主要為大家詳細(xì)介紹了使用CursorLoader異步加載數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

下面是一個(gè)例子:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/zzqLivecn/article/details/7896297

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产精品中文字幕在线 | 欧美淫片| 亚洲午夜免费视频 | 国产电影一区二区 | 欧美精品一二区 | 日韩成人在线观看 | 亚洲国产精品一区二区第一页 | 涩涩视频在线看 | 国产精品自产拍在线观看桃花 | 国产精品1区 | 国产综合久久 | 精品久久久久久久久久久 | 久久天天 | 伊人激情网| 国产精品高潮呻吟久久 | 欧美日韩一区二区三区在线观看 | 一级片免费视频 | 日韩一区在线视频 | av网站一区 | 视频一二区 | 久久99精品国产麻豆婷婷洗澡 | 国产欧美一区二区精品久久 | 日韩视频在线观看 | 日韩免费av一区二区 | 久久成人18免费网站 | 亚洲精品999 | 激情五月婷婷综合 | 成人羞羞视频免费 | 夜夜春精品视频高清69式 | 国产免费一级特黄录像 | 欧美va视频 | 日本久久网 | 亚洲精品在线免费 | 五月婷婷综合激情网 | 四虎久久 | 日韩国产欧美视频 | 麻豆av在线播放 | 91麻豆蜜桃一区二区三区 | 成人精品福利 | 日韩在线精品视频 | 亚洲成av人片在线观看 |