當前位置: 首頁>>代碼示例>>Java>>正文


Java CursorAdapter類代碼示例

本文整理匯總了Java中android.widget.CursorAdapter的典型用法代碼示例。如果您正苦於以下問題:Java CursorAdapter類的具體用法?Java CursorAdapter怎麽用?Java CursorAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CursorAdapter類屬於android.widget包,在下文中一共展示了CursorAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: queryData

import android.widget.CursorAdapter; //導入依賴的package包/類
/**
 * 關注1
 * 模糊查詢數據 & 顯示到ListView列表上
 */
private void queryData(String tempName) {

    // 1. 模糊搜索
    Cursor cursor = helper.getReadableDatabase().rawQuery(
            "select id as _id,name from Search where name like '%" + tempName + "%' order by id desc ", null);
    // 2. 創建adapter適配器對象 & 裝入模糊搜索的結果
    adapter = new SimpleCursorAdapter(mContext, android.R.layout.simple_list_item_1, cursor, new String[] { "name" },
            new int[] { android.R.id.text1 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    // 3. 設置適配器
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

    System.out.println(cursor.getCount());
    // 當輸入框為空 & 數據庫中有搜索記錄時,顯示 "刪除搜索記錄"按鈕
    if (tempName.equals("") && cursor.getCount() != 0){
        tv_clear.setVisibility(VISIBLE);
    }
    else {
        tv_clear.setVisibility(INVISIBLE);
    };

}
 
開發者ID:AndroidBoySC,項目名稱:Mybilibili,代碼行數:27,代碼來源:MySearchView.java

示例2: delete

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
    final RoadModel road = (RoadModel) model;
    if (road.isDefaultRoad()) {
        showDefaultProjectToast();
        return;
    }
    new AsyncTask<Void, Void, Cursor>() {

        @Override
        protected Cursor doInBackground(Void[] params) {
            MeasurementsDataHelper.getInstance().deleteRoad(road.getId(), true);
            final Cursor cursor = roadDAO.getAllRoadByFolderIdCursor(((RoadModel) model).getFolderId());
            return cursor;
        }

        @Override
        protected void onPostExecute(Cursor o) {
            super.onPostExecute(o);
            ((CursorAdapter)getAdapter()).swapCursor(o);
        }
    }.execute();
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:24,代碼來源:RoadListFragment.java

示例3: delete

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
    new AsyncTask<Void, Void, Cursor>() {
        @Override
        protected Cursor doInBackground(Void[] params) {
            MeasurementModel measurement = (MeasurementModel) model;
            MeasurementsDataHelper.getInstance().deleteMeasurement(measurement.getId(), true);
            final Cursor cursor = measurementDAO.getAllMeasurementByRoadIdCursor(roadModel.getId());
            return cursor;
        }
        @Override
        protected void onPostExecute(Cursor o) {
            super.onPostExecute(o);
            ((CursorAdapter)getAdapter()).swapCursor(o);
        }
    }.execute();
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:18,代碼來源:MeasurementListFragment.java

示例4: delete

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
    final FolderModel project = (FolderModel) model;
    if (project.isDefaultProject()) {
        showDefaultProjectToast();
        return;
    }
    new AsyncTask<Void, Void, Cursor>() {
        @Override
        protected Cursor doInBackground(Void[] params) {
            MeasurementsDataHelper.getInstance().deleteProject(project.getId(), true);
            final Cursor cursor = folderDAO.getAllFolderCursor();
            return cursor;
        }
        @Override
        protected void onPostExecute(Cursor o) {
            super.onPostExecute(o);
            ((CursorAdapter)getAdapter()).swapCursor(o);
        }
    }.execute();
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:22,代碼來源:FolderListFragment.java

示例5: refreshFolders

import android.widget.CursorAdapter; //導入依賴的package包/類
public void refreshFolders() {
    new AsyncTask<Void, Void, Cursor>() {
        @Override
        protected Cursor doInBackground(Void[] params) {
            //long folderId = folderDAO.putFolder(folderModel);
            MeasurementsDataHelper.getInstance().refreshFoldersCountersSync();
            final Cursor cursor = folderDAO.getAllFolderCursor();
            return cursor;
        }
        @Override
        protected void onPostExecute(Cursor o) {
            super.onPostExecute(o);
            ((CursorAdapter)getAdapter()).swapCursor(o);
        }
    }.execute();
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:17,代碼來源:FolderListFragment.java

示例6: delete

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
    new AsyncTask<Void, Void, Cursor>() {
        @Override
        protected Cursor doInBackground(Void[] params) {
            TagModel tagModel = (TagModel) model;
            tagDAO.delete(tagModel);
            final Cursor cursor = tagDAO.
            getTagsByRoadIdCursor(RAApplication.getInstance().getCurrentRoadId());
            return cursor;
        }

        @Override
        protected void onPostExecute(Cursor o) {
            ((CursorAdapter) getAdapter()).swapCursor(o);
        }
    }.execute();
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:19,代碼來源:TagsListFragment.java

示例7: swapCursor

import android.widget.CursorAdapter; //導入依賴的package包/類
private void swapCursor(){

        int offsetFromTop = 0;
        int firstVisiblePosition = Math.max(0, feedListView.getFirstVisiblePosition());
        if(feedListView.getChildCount() > 0) {
            offsetFromTop = feedListView.getChildAt(0).getTop();
        }

        CursorAdapter newAdapter = ((CursorAdapter) feedListView.getAdapter());
        newAdapter.swapCursor(getCursor());
        if(SearchHelper.searchToSQL(query) == null) {
            ((FeedAdapter) newAdapter).setHighlight(Utils.getKeywords(query));
        }
        feedListView.setAdapter(newAdapter);

        feedListView.setSelectionFromTop(firstVisiblePosition, offsetFromTop);
    }
 
開發者ID:casific,項目名稱:murmur,代碼行數:18,代碼來源:StarredFragment.java

示例8: setListInSelectionMode

import android.widget.CursorAdapter; //導入依賴的package包/類
private void setListInSelectionMode(){

        inSelectionMode = true;

        ((FeedAdapter) feedListView.getAdapter()).setSelectionMode(true);
        swapCursor();
        feedListView.setOnItemLongClickListener(null);
        feedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Cursor c = ((CursorAdapter) feedListView.getAdapter()).getCursor();
                c.moveToPosition(position);
                boolean isChecked = c.getInt(c.getColumnIndex(MessageStore.COL_CHECKED)) == MessageStore.TRUE;
                String message = c.getString(c.getColumnIndex(MessageStore.COL_MESSAGE));

                MessageStore.getInstance(getActivity()).checkMessage(message, !isChecked);
                swapCursor();
                setActionbar();

            }
        });
        setActionbar();

        newPostButton.setVisibility(View.INVISIBLE);
    }
 
開發者ID:casific,項目名稱:murmur,代碼行數:26,代碼來源:StarredFragment.java

示例9: swapCursor

import android.widget.CursorAdapter; //導入依賴的package包/類
private void swapCursor(){

        int offsetFromTop = 0;
        int firstVisiblePosition = Math.max(0, contactListView.getFirstVisiblePosition());
        if(contactListView.getChildCount() > 0) {
            offsetFromTop = contactListView.getChildAt(0).getTop();
        }

        CursorAdapter newAdapter = ((CursorAdapter) contactListView.getAdapter());
        newAdapter.swapCursor(getCursor());
        if(SearchHelper.searchToSQL(query) == null) {
            ((ContactAdapter) newAdapter).setHighlight(Utils.getKeywords(query));
        }
        contactListView.setAdapter(newAdapter);

        contactListView.setSelectionFromTop(firstVisiblePosition, offsetFromTop);
    }
 
開發者ID:casific,項目名稱:murmur,代碼行數:18,代碼來源:ContactsFragment.java

示例10: swapCursor

import android.widget.CursorAdapter; //導入依賴的package包/類
private void swapCursor(){

        int offsetFromTop = 0;
        int firstVisiblePosition = Math.max(0, listView.getFirstVisiblePosition());
        if(listView.getChildCount() > 0) {
            offsetFromTop = listView.getChildAt(0).getTop();
        }

        CursorAdapter newAdapter = ((CursorAdapter) listView.getAdapter());
        newAdapter.swapCursor(getCursor());
        if(SearchHelper.searchToSQL(query) == null) {
            ((FeedReplyAdapter) newAdapter).setHighlight(Utils.getKeywords(query));
        }
        listView.setAdapter(newAdapter);

        listView.setSelectionFromTop(firstVisiblePosition, offsetFromTop);
        parentMessage.setAdapter(new FeedAdapter(getActivity(), MessageStore.getInstance(getActivity()).getMessageById(messageId), false, feedAdapterCallbacks));
    }
 
開發者ID:casific,項目名稱:murmur,代碼行數:19,代碼來源:ExpandedMessageFragment.java

示例11: queryData

import android.widget.CursorAdapter; //導入依賴的package包/類
/**
 * 關注1
 * 模糊查詢數據 & 顯示到ListView列表上
 */
private void queryData(String tempName) {

    // 1. 模糊搜索
    Cursor cursor = helper.getReadableDatabase().rawQuery(
            "select id as _id,name from records where name like '%" + tempName + "%' order by id desc ", null);
    // 2. 創建adapter適配器對象 & 裝入模糊搜索的結果
    adapter = new SimpleCursorAdapter(context, android.R.layout.simple_list_item_1, cursor, new String[] { "name" },
            new int[] { android.R.id.text1 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    // 3. 設置適配器
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

    System.out.println(cursor.getCount());
    // 當輸入框為空 & 數據庫中有搜索記錄時,顯示 "刪除搜索記錄"按鈕
    if (tempName.equals("") && cursor.getCount() != 0){
        tv_clear.setVisibility(VISIBLE);
    }
    else {
        tv_clear.setVisibility(INVISIBLE);
    };

}
 
開發者ID:Carson-Ho,項目名稱:Search_Layout,代碼行數:27,代碼來源:SearchView.java

示例12: handleSelectAll

import android.widget.CursorAdapter; //導入依賴的package包/類
private void handleSelectAll() {
  selectedContacts.clear();

  Cursor cursor = null;

  try {
    cursor = ContactAccessor.getInstance().getCursorForContactsWithNumbers(getActivity());

    while (cursor != null && cursor.moveToNext()) {
      ContactData contactData = ContactAccessor.getInstance().getContactData(getActivity(), cursor);

      if      (contactData.numbers.isEmpty())   continue;
      else if (contactData.numbers.size() == 1) addSingleNumberContact(contactData);
      else                                      addMultipleNumberContact(contactData, null);
    }
  } finally {
    if (cursor != null)
      cursor.close();
  }

  ((CursorAdapter)getListView().getAdapter()).notifyDataSetChanged();
}
 
開發者ID:redcracker,項目名稱:TextSecure,代碼行數:23,代碼來源:ContactSelectionListFragment.java

示例13: onCreate

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_conversation);

    Bundle extras = getIntent().getExtras();

    mShowSentMessages = extras.getBoolean("sentMessages", false);

    if(mShowSentMessages) {
        getActionBar().setTitle(R.string.sent_messages);
    } else {
        mUserId = extras.getString("fromUserId");
        String userEmail = extras.getString("fromUserEmail");

        getActionBar().setTitle(userEmail);
    }

    final ListAdapter adapter = new ConversationAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    getListView().setAdapter(adapter);
    getLoaderManager().initLoader(0, null, this);
}
 
開發者ID:cat-chat,項目名稱:cat-chat-android,代碼行數:24,代碼來源:ConversationActivity.java

示例14: onCreate

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ListView listDrinks = getListView();

    try {
        SQLiteOpenHelper starbuzzDatabaseHelper = new StarbuzzDatabaseHelper(this);
        db = starbuzzDatabaseHelper.getReadableDatabase();

        cursor = db.query("DRINK",
                          new String[]{"_id", "NAME"},
                          null, null, null, null, null);

        CursorAdapter listAdapter = new SimpleCursorAdapter(this,
                                                            android.R.layout.simple_list_item_1,
                                                            cursor,
                                                            new String[]{"NAME"},
                                                            new int[]{android.R.id.text1},
                                                            0);
        listDrinks.setAdapter(listAdapter);
    } catch(SQLiteException e) {
        Toast toast = Toast.makeText(this, "Database unavailable", Toast.LENGTH_SHORT);
        toast.show();
    }
}
 
開發者ID:dogriffiths,項目名稱:HeadFirstAndroid,代碼行數:26,代碼來源:DrinkCategoryActivity.java

示例15: onRestart

import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
public void onRestart() {
    super.onRestart();
    try {
        StarbuzzDatabaseHelper starbuzzDatabaseHelper = new StarbuzzDatabaseHelper(this);
        db = starbuzzDatabaseHelper.getReadableDatabase();
        Cursor newCursor = db.query("DRINK",
                                    new String[] { "_id", "NAME"},
                                    "FAVORITE = 1",
                                    null, null, null, null);
        ListView listFavorites = (ListView)findViewById(R.id.list_favorites);
        CursorAdapter adapter = (CursorAdapter) listFavorites.getAdapter();
        adapter.changeCursor(newCursor);
        favoritesCursor = newCursor;
    } catch(SQLiteException e) {
        Toast toast = Toast.makeText(this, "Database unavailable", Toast.LENGTH_SHORT);
        toast.show();
    }
}
 
開發者ID:dogriffiths,項目名稱:HeadFirstAndroid,代碼行數:20,代碼來源:TopLevelActivity.java


注:本文中的android.widget.CursorAdapter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。