Search in sources :

Example 1 with SimpleCursorAdapter

use of android.support.v4.widget.SimpleCursorAdapter in project AndroidTraining by mixi-inc.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ListView listView = (ListView) findViewById(R.id.ListView);
    // UIにバインドするデータのカラム名
    String[] from = { Book.COLUMN_NAME_BOOK_TITLE, Book.COLUMN_NAME_BOOK_PRICE };
    // 指定したカラムのデータを表示するViewのIDを指定します。
    int[] to = { R.id.Title, R.id.Price };
    final Cursor cursor = getContentResolver().query(Book.CONTENT_URI, null, null, null, null);
    // Cursorのデータが更新されたことを通知する
    // BookContentProviderでsetNotificationUri()をしないと動作しない
    cursor.registerContentObserver(new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            cursor.requery();
        }
    });
    mSimpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.list_item_book, cursor, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    listView.setAdapter(mSimpleCursorAdapter);
    findViewById(R.id.ADD).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            insert();
        }
    });
}
Also used : ListView(android.widget.ListView) SimpleCursorAdapter(android.support.v4.widget.SimpleCursorAdapter) Handler(android.os.Handler) OnClickListener(android.view.View.OnClickListener) Cursor(android.database.Cursor) View(android.view.View) ListView(android.widget.ListView) ContentObserver(android.database.ContentObserver)

Example 2 with SimpleCursorAdapter

use of android.support.v4.widget.SimpleCursorAdapter in project Zom-Android by zom.

the class AddContactActivity method setupAccountSpinner.

private void setupAccountSpinner() {
    final Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;
    mCursorProviders = managedQuery(uri, PROVIDER_PROJECTION, Imps.Provider.CATEGORY + "=?" + " AND " + Imps.Provider.ACTIVE_ACCOUNT_USERNAME + " NOT NULL", /* selection */
    new String[] { ImApp.IMPS_CATEGORY }, /* selection args */
    Imps.Provider.DEFAULT_SORT_ORDER);
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, mCursorProviders, new String[] { Imps.Provider.ACTIVE_ACCOUNT_USERNAME }, new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // TODO Something is causing the managedQuery() to return null, use null guard for now
    if (mCursorProviders != null && mCursorProviders.getCount() > 0) {
        mCursorProviders.moveToFirst();
        mProviderId = mCursorProviders.getLong(PROVIDER_ID_COLUMN);
        mAccountId = mCursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
    }
/**
 *        mListSpinner.setAdapter(adapter);
 *        mListSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
 *
 *            @Override
 *            public void onItemSelected(AdapterView<?> arg0, View arg1,
 *                    int arg2, long arg3) {
 *                if (mCursorProviders == null)
 *                    return;
 *                mCursorProviders.moveToPosition(arg2);
 *                mProviderId = mCursorProviders.getLong(PROVIDER_ID_COLUMN);
 *                mAccountId = mCursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
 *             }
 *
 *            @Override
 *            public void onNothingSelected(AdapterView<?> arg0) {
 *                // TODO Auto-generated method stub
 *
 *            }
 *        });
 */
}
Also used : SimpleCursorAdapter(android.support.v4.widget.SimpleCursorAdapter) Uri(android.net.Uri)

Example 3 with SimpleCursorAdapter

use of android.support.v4.widget.SimpleCursorAdapter in project YalpStore by yeriomin.

the class BaseActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSubmitButtonEnabled(true);
    suggestionsAdapter = new SimpleCursorAdapter(this, R.layout.suggestion_list_item, null, new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_ICON_1 }, new int[] { R.id.text, R.id.icon }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    searchView.setSuggestionsAdapter(suggestionsAdapter);
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {

        @Override
        public boolean onSuggestionClick(int position) {
            triggerSearch((Cursor) suggestionsAdapter.getItem(position));
            return true;
        }

        @Override
        public boolean onSuggestionSelect(int position) {
            triggerSearch((Cursor) suggestionsAdapter.getItem(position));
            return true;
        }

        private void triggerSearch(Cursor cursor) {
            String data = cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA));
            String label = cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
            search(data, !data.equals(label));
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            search(s, false);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            new SearchSuggestionTask(BaseActivity.this).execute(s);
            return false;
        }
    });
    return result;
}
Also used : SearchView(android.support.v7.widget.SearchView) SimpleCursorAdapter(android.support.v4.widget.SimpleCursorAdapter) Cursor(android.database.Cursor)

Example 4 with SimpleCursorAdapter

use of android.support.v4.widget.SimpleCursorAdapter in project Brion-Learns-OAuth by brione.

the class BloaUserTimelineFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    this.setEmptyText(this.getString(R.string.empty));
    // No cursor yet. Will be assigned when the CursorLoader query is complete
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this.getActivity(), android.R.layout.simple_list_item_2, null, App.USER_STATUS_PROJECTION, IDS, 0);
    setListAdapter(adapter);
    // Set up our cursor loader. It manages the cursors from now on
    getLoaderManager().initLoader(App.LIST_LOADER_ID, null, this);
}
Also used : SimpleCursorAdapter(android.support.v4.widget.SimpleCursorAdapter)

Example 5 with SimpleCursorAdapter

use of android.support.v4.widget.SimpleCursorAdapter in project ButterRemote-Android by se-bastiaan.

the class InstanceListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);
    getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    getListView().setOnItemLongClickListener(mOnLongClickListener);
    getListView().setSelector(R.drawable.selectable_background_popcorntimeremote);
    int horizontalMargin = getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
    int verticalMargin = getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin);
    int actionBarHeight = getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material);
    int statusBarHeight = 0;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        statusBarHeight = PixelUtils.getStatusBarHeight(getActivity());
    }
    getListView().setPadding(horizontalMargin, verticalMargin + actionBarHeight + statusBarHeight, horizontalMargin, verticalMargin);
    mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.fragment_listinstance_item, null, new String[] { InstanceEntry.COLUMN_NAME_NAME, InstanceEntry.COLUMN_NAME_IP }, new int[] { R.id.text1, R.id.text2 }, 0);
    getLoaderManager().initLoader(0, null, this);
    listView.setOnItemClickListener(mClickListener);
}
Also used : SimpleCursorAdapter(android.support.v4.widget.SimpleCursorAdapter)

Aggregations

SimpleCursorAdapter (android.support.v4.widget.SimpleCursorAdapter)12 ListView (android.widget.ListView)7 View (android.view.View)6 Cursor (android.database.Cursor)5 OnClickListener (android.view.View.OnClickListener)3 TextView (android.widget.TextView)3 SearchView (android.support.v7.widget.SearchView)2 AdapterView (android.widget.AdapterView)2 Context (android.content.Context)1 TypedArray (android.content.res.TypedArray)1 ContentObserver (android.database.ContentObserver)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 LoaderManager (android.support.v4.app.LoaderManager)1 Toolbar (android.support.v7.widget.Toolbar)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Time (android.text.format.Time)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 StyleSpan (android.text.style.StyleSpan)1