android.widget.CursorAdapter Java Examples

The following examples show how to use android.widget.CursorAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchView.java    From Search_Layout with MIT License 6 votes vote down vote up
/**
 * 关注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);
    };

}
 
Example #2
Source File: DrinkCategoryActivity.java    From HeadFirstAndroid with MIT License 6 votes vote down vote up
@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();
    }
}
 
Example #3
Source File: TopLevelActivity.java    From HeadFirstAndroid with MIT License 6 votes vote down vote up
@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();
    }
}
 
Example #4
Source File: CircularViewCursorAdapter.java    From CircularView with Apache License 2.0 6 votes vote down vote up
void init(final Cursor c, int flags) {
    if ((flags & CursorAdapter.FLAG_AUTO_REQUERY) == CursorAdapter.FLAG_AUTO_REQUERY) {
        flags |= CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER;
        mAutoRequery = true;
    } else {
        mAutoRequery = false;
    }
    boolean cursorPresent = c != null;
    mCursor = c;
    mDataValid = cursorPresent;
    mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
    if ((flags & CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) == CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) {
        mChangeObserver = new ChangeObserver();
        mDataSetObserver = new MyDataSetObserver();
    } else {
        mChangeObserver = null;
        mDataSetObserver = null;
    }

    if (cursorPresent) {
        if (mChangeObserver != null) c.registerContentObserver(mChangeObserver);
        if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver);
    }
}
 
Example #5
Source File: PoemHistoryActivity.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
private void setUpPoemList() {
    shareListener = new OnShareClickListener();
    deleteListener = new OnDeleteClickListener();

    final ListView poemsList = (ListView) findViewById(R.id.poem_history_list);

    adapter = new PoemCursorAdapter(
            getApplicationContext(),
            null,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    // MoPub integration
    final ViewBinder mopubViewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)
            .mainImageId(R.id.native_ad_main_image)
            .iconImageId(R.id.native_ad_icon_image)
            .titleId(R.id.native_ad_title)
            .textId(R.id.native_ad_text)
            .build();

    MoPubNativeAdPositioning.MoPubServerPositioning adPositioning =
            MoPubNativeAdPositioning.serverPositioning();
    final MoPubNativeAdRenderer adRenderer = new MoPubNativeAdRenderer(mopubViewBinder);
    moPubAdAdapter = new MoPubAdAdapter(this, adapter, adPositioning);
    moPubAdAdapter.registerAdRenderer(adRenderer);

    poemsList.setAdapter(moPubAdAdapter);
}
 
Example #6
Source File: ArcaAdapterFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void setupAdapterView(final View view, final Bundle savedInstanceState) {
       mAdapterView = (AdapterView<CursorAdapter>) view.findViewById(getAdapterViewId());

       mAdapter = onCreateAdapter(mAdapterView, savedInstanceState);

       mAdapterView.setAdapter(mAdapter);
}
 
Example #7
Source File: ArcaSimpleAdapterFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public CursorAdapter onCreateAdapter(final AdapterView<CursorAdapter> adapterView, final Bundle savedInstanceState) {
    final int layout = FragmentUtils.getAdapterItemLayout(this.getClass());
    final Collection<Binding> bindings = FragmentUtils.getBindings(this.getClass());
    final ModernCursorAdapter adapter = new ModernCursorAdapter(getActivity(), layout, bindings);
    adapter.setViewBinder(FragmentUtils.createViewBinder(this.getClass()));
    return adapter;
}
 
Example #8
Source File: AdapterRule.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewRecycled(ViewHolder holder) {
    super.onViewRecycled(holder);

    //Context context = holder.itemView.getContext();
    //GlideApp.with(context).clear(holder.ivIcon);

    CursorAdapter adapter = (CursorAdapter) holder.lvAccess.getAdapter();
    if (adapter != null) {
        Log.i(TAG, "Closing access cursor");
        adapter.changeCursor(null);
        holder.lvAccess.setAdapter(null);
    }
}
 
Example #9
Source File: LyricExplorerFragment.java    From LyricHere with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mAdapter = new LyricCursorAdapter(getActivity(), R.layout.explorer_item,
            null, FROM, TO, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mAdapter.setViewBinder(VIEW_BINDER);

    setListAdapter(mAdapter);

    // Done on a separate thread
    getLoaderManager().initLoader(LOADER_ID, null, this);

    registerForContextMenu(getListView());
    getListView().setTextFilterEnabled(true);
}
 
Example #10
Source File: ArcaItemFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void bindViewAtPosition(final int position) {
	final CursorAdapter adapter = getCursorAdapter();
	final Cursor cursor = adapter.getCursor();
	if (cursor != null && cursor.moveToPosition(position)) {
		adapter.bindView(getView(), getActivity(), cursor);
	}
}
 
Example #11
Source File: ArcaSimpleItemFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public CursorAdapter onCreateAdapter(final View view, final Bundle savedInstanceState) {
    final Collection<Binding> bindings = FragmentUtils.getBindings(this.getClass());
    final ModernItemAdapter adapter = new ModernItemAdapter(getActivity(), bindings);
    adapter.setViewBinder(FragmentUtils.createViewBinder(this.getClass()));
    return adapter;
}
 
Example #12
Source File: DashboardMostUtilizedFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
private void setLoader() {
    CursorAdapter listAdapter = new MostUtilizedListAdapter(getActivity(), null, ACTIVE_LOADER);

    if (dashboardType == DashboardType.PHYSICAL) {
        cursorAdapterLoader = new CursorAdapterLoader(listAdapter) {
            @Override
            public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
                return DashboardHelper.querySelection(provider, Host.class, activeSelection)
                        .orderByDescending(CPU_USAGE)
                        .limit(page * ITEMS_PER_PAGE)
                        .asLoader();
            }
        };
    } else {
        cursorAdapterLoader = new CursorAdapterLoader(listAdapter) {
            @Override
            public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
                return DashboardHelper.querySelection(provider, Vm.class, activeSelection)
                        .orderByDescending(CPU_USAGE)
                        .limit(page * ITEMS_PER_PAGE)
                        .asLoader();
            }
        };
    }

    listView.setAdapter(listAdapter);
}
 
Example #13
Source File: BaseListFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
protected void initAdapters() {
    final CursorAdapter cursorAdapter = createCursorAdapter();

    listView.setAdapter(cursorAdapter);
    listView.setEmptyView(getActivity().findViewById(android.R.id.empty));
    listView.setTextFilterEnabled(true);

    cursorAdapterLoader = new CursorAdapterLoader(cursorAdapter) {
        @Override
        public synchronized Loader<Cursor> onCreateLoader(int id, Bundle args) {
            ProviderFacade.QueryBuilder<E> query = provider.query(entityClass);

            appendQuery(query);

            final CustomSort customSort = getCustomSort();

            if (customSort == null) {
                final SortEntry orderBy = (SortEntry) orderBySpinner.getSelectedItem();
                final SortOrder order = SortOrderType.getSortOrder((String) orderSpinner.getSelectedItem());
                query.orderBy(orderBy.orderBySql(), order);
            } else {
                for (CustomSort.CustomSortEntry entry : customSort.getSortEntries()) {
                    query.orderBy(entry.getColumnName(), entry.getSortOrder());
                }
            }

            return query.limit(page * ITEMS_PER_PAGE).asLoader();
        }
    };

    getLoaderManager().initLoader(BASE_LOADER, null, cursorAdapterLoader);
}
 
Example #14
Source File: VmSnapshotsFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter snapshotListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.snapshot_list_item,
            null,
            new String[]{NAME, SNAPSHOT_STATUS, DATE, PERSIST_MEMORYSTATE},
            new int[]{R.id.snapshot_description, R.id.snapshot_status, R.id.snapshot_date, R.id.snapshot_persist_memorystate}, 0);
    snapshotListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;

            if (columnIndex == cursor.getColumnIndex(NAME)) {
                String name = cursor.getString(columnIndex);
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(DATE)) {
                String date = DateUtils.convertDateToString(getActivity(), cursor.getLong(columnIndex));
                textView.setText(date);
            } else if (columnIndex == cursor.getColumnIndex(SNAPSHOT_STATUS)) {
                String status = cursor.getString(columnIndex);
                textView.setText(status == null ? getString(R.string.NA) : status.replace("_", " ").toUpperCase());
            } else if (columnIndex == cursor.getColumnIndex(PERSIST_MEMORYSTATE)) {
                textView.setText(getString(R.string.snapshot_memory));
                textView.setVisibility((new CursorHelper(cursor)).getBoolean(columnIndex) ? View.VISIBLE : View.GONE);
            }

            return true;
        }
    });

    return snapshotListAdapter;
}
 
Example #15
Source File: VmDisksFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter diskListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.disk_list_item,
            null,
            new String[]{NAME, SIZE, STATUS},
            new int[]{R.id.disk_name, R.id.disk_size, R.id.disk_status}, 0);
    diskListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;

            if (columnIndex == cursor.getColumnIndex(NAME)) {
                String name = cursor.getString(columnIndex);
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(SIZE)) {
                long size = cursor.getLong(columnIndex);
                String sizeText = (size == -1) ? getString(R.string.disk_unknown_size) : new MemorySize(size).toString();
                textView.setText(sizeText);
            } else if (columnIndex == cursor.getColumnIndex(STATUS)) {
                String status = cursor.getString(columnIndex);
                textView.setText(status == null ? getString(R.string.NA) : status.toUpperCase());
            }

            return true;
        }
    });

    return diskListAdapter;
}
 
Example #16
Source File: StorageDomainFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter storageDomainListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.storage_domain_list_item,
            null,
            new String[]{NAME, STATUS},
            new int[]{R.id.storage_domain_name, R.id.storage_domain_status}, 0);

    storageDomainListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex == cursor.getColumnIndex(NAME)) {
                TextView textView = (TextView) view;
                String name = cursor.getString(cursor.getColumnIndex(NAME));
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(STATUS)) {
                ImageView imageView = (ImageView) view;
                String statusString = cursor.getString(cursor.getColumnIndex(STATUS));
                imageView.setImageResource(StorageDomainStatus.fromString(statusString).getResource());
            }

            return true;
        }
    });

    return storageDomainListAdapter;
}
 
Example #17
Source File: SnapshotDisksFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter diskListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.disk_list_item,
            null,
            new String[]{NAME, SIZE, STATUS},
            new int[]{R.id.disk_name, R.id.disk_size, R.id.disk_status}, 0);
    diskListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;

            if (columnIndex == cursor.getColumnIndex(NAME)) {
                String name = cursor.getString(columnIndex);
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(SIZE)) {
                long size = cursor.getLong(columnIndex);
                String sizeText = (size == -1) ? getString(R.string.disk_unknown_size) : new MemorySize(size).toString();
                textView.setText(sizeText);
            } else if (columnIndex == cursor.getColumnIndex(STATUS)) {
                String status = cursor.getString(columnIndex);
                textView.setText(status == null ? getString(R.string.NA) : status.toUpperCase());
            }

            return true;
        }
    });

    return diskListAdapter;
}
 
Example #18
Source File: SessionManagerActivity.java    From sniffer154 with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.session_manager_activity);
	mListViewSessions = (ListView) findViewById(R.id.listViewSessions);
	getLoaderManager().initLoader(0, null,
			new SessionLoaderCallbacks());
	mAdapter = new SimpleCursorAdapter(this, R.layout.session_list_row,
			null, FROM, TO, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
	mAdapter.setViewBinder(new SessionViewBinder());
	mListViewSessions.setAdapter(mAdapter);
	mListViewSessions
			.setOnItemClickListener(new SessionOnItemClickListener());
	registerForContextMenu(mListViewSessions);
}
 
Example #19
Source File: SearchViewAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
public SearchViewAssert hasSuggestionsAdapter(CursorAdapter adapter) {
  isNotNull();
  CursorAdapter actualAdapter = actual.getSuggestionsAdapter();
  assertThat(actualAdapter) //
      .overridingErrorMessage("Expected suggestions adapter <%s> but was <%s>.", adapter,
          actualAdapter) //
      .isSameAs(adapter);
  return this;
}
 
Example #20
Source File: AdapterRule.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewRecycled(ViewHolder holder) {
    super.onViewRecycled(holder);

    //Context context = holder.itemView.getContext();
    //GlideApp.with(context).clear(holder.ivIcon);

    CursorAdapter adapter = (CursorAdapter) holder.lvAccess.getAdapter();
    if (adapter != null) {
        Log.i(TAG, "Closing access cursor");
        adapter.changeCursor(null);
        holder.lvAccess.setAdapter(null);
    }
}
 
Example #21
Source File: CursorAdapterAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public CursorAdapterAssert(CursorAdapter actual) {
  super(actual, CursorAdapterAssert.class);
}
 
Example #22
Source File: NoteLoaderCallback.java    From droitatedDB with Apache License 2.0 4 votes vote down vote up
public NoteLoaderCallback(final Context context, final CursorAdapter cursorAdapter, final int loaderId) {
	this.context = context;
	this.cursorAdapter = cursorAdapter;
	this.loaderId = loaderId;
}
 
Example #23
Source File: EventsFragment.java    From moVirt with Apache License 2.0 4 votes vote down vote up
protected CursorAdapter createCursorAdapter() {
    return new EventsCursorAdapter(getActivity());
}
 
Example #24
Source File: CursorAdapterLoader.java    From moVirt with Apache License 2.0 4 votes vote down vote up
public CursorAdapterLoader(CursorAdapter cursorAdapter) {
    this.cursorAdapter = cursorAdapter;
}
 
Example #25
Source File: ArcaItemFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CursorAdapter getCursorAdapter() {
	return mAdapter;
}
 
Example #26
Source File: TopicListFragment.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected CursorAdapter buildListAdapter() {
	return new TopicAdapter(getActivity());
}
 
Example #27
Source File: ArcaAdapterFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CursorAdapter getCursorAdapter() {
	return mAdapter;
}
 
Example #28
Source File: ArcaAdapterFragment.java    From arca-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public AdapterView<CursorAdapter> getAdapterView() {
	return mAdapterView;
}
 
Example #29
Source File: VideoItemFragment.java    From android-tv-leanback with Apache License 2.0 4 votes vote down vote up
@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
    ((CursorAdapter) mGridView.getAdapter()).swapCursor(null);
}
 
Example #30
Source File: ToolbarSpinner.java    From FilePicker with MIT License 4 votes vote down vote up
public void setAdapter(CursorAdapter adapter) {
    mListPopupWindow.setAdapter(adapter);
    mAdapter = adapter;
}