Java Code Examples for android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER

The following examples show how to use android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER . 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: 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 3
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 4
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 5
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);
}