当前位置: 首页>>代码示例>>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;未经允许,请勿转载。