Example usage for android.widget SimpleCursorAdapter getCursor

List of usage examples for android.widget SimpleCursorAdapter getCursor

Introduction

In this page you can find the example usage for android.widget SimpleCursorAdapter getCursor.

Prototype

public Cursor getCursor() 

Source Link

Document

Returns the cursor.

Usage

From source file:whipkey.stemesteem.components.StemListFragment.java

public void onListItemClick(ListView l, View v, int position, long id) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) l.getAdapter();
    Cursor c = adapter.getCursor();

    c.moveToPosition(position);/*from   w  w  w  . ja  v a 2 s.c om*/
    int weekNo = c.getInt(c.getColumnIndex("weekNo"));
    int stemNo = c.getInt(c.getColumnIndex("stemNo"));
    String stem = c.getString(c.getColumnIndex("stem"));
    clickListener.stemListItemClick(weekNo, stemNo, stem); // call back to
    // our activity,
    // requesting
    // the
    // currentWeek's
    // value so that
    // our listview
    // can be
    // updated.
}

From source file:com.money.manager.ex.investment.watchlist.WatchlistFragment.java

/**
 * Select the current account in the accounts dropdown.
 *//*from w ww  .ja  va2  s  .  c o m*/
private void selectCurrentAccount() {
    Spinner spinner = getAccountsSpinner();
    if (spinner == null)
        return;

    // find account
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) spinner.getAdapter();
    if (adapter == null)
        return;

    Cursor cursor = adapter.getCursor();
    int position = Constants.NOT_SET;

    for (int i = 0; i < adapter.getCount(); i++) {
        cursor.moveToPosition(i);
        String accountIdString = cursor.getString(cursor.getColumnIndex(Account.ACCOUNTID));
        int accountId = Integer.parseInt(accountIdString);
        if (accountId == getAccountId()) {
            position = i;
            break;
        }
    }

    spinner.setSelection(position);
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

/**
 * Select the current account in the accounts dropdown.
 *///w  ww. ja v a2 s.  c  om
private void selectCurrentAccount() {
    Spinner spinner = getAccountsSpinner();
    if (spinner == null)
        return;

    // find account
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) spinner.getAdapter();
    if (adapter == null)
        return;

    Cursor cursor = adapter.getCursor();
    int position = Constants.NOT_SET;

    for (int i = 0; i < adapter.getCount(); i++) {
        cursor.moveToPosition(i);
        String accountIdString = cursor.getString(cursor.getColumnIndex(Account.ACCOUNTID));
        int accountId = Integer.parseInt(accountIdString);
        if (accountId == mAccountId) {
            position = i;
            break;
        }
    }

    spinner.setSelection(position);
}

From source file:com.ultramegasoft.flavordex2.util.EntryFormHelper.java

/**
 * Set up the autocomplete for the maker field.
 *//*from w w w  .j a  va  2s  . c om*/
private void setupMakersAutoComplete() {
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(mFragment.getContext(),
            R.layout.simple_dropdown_item_2line, null,
            new String[] { Tables.Makers.NAME, Tables.Makers.LOCATION },
            new int[] { android.R.id.text1, android.R.id.text2 }, 0);

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence constraint) {
            final Uri uri;
            if (TextUtils.isEmpty(constraint)) {
                uri = Tables.Makers.CONTENT_URI;
            } else {
                uri = Uri.withAppendedPath(Tables.Makers.CONTENT_FILTER_URI_BASE,
                        Uri.encode(constraint.toString()));
            }

            final Bundle args = new Bundle();
            args.putParcelable("uri", uri);

            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mFragment.getLoaderManager().restartLoader(LOADER_MAKERS, args, EntryFormHelper.this);
                }
            });

            return adapter.getCursor();
        }
    });

    mTxtMaker.setAdapter(adapter);

    // fill in maker and origin fields with a suggestion
    mTxtMaker.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            cursor.moveToPosition(position);

            final String name = cursor.getString(cursor.getColumnIndex(Tables.Makers.NAME));
            final String origin = cursor.getString(cursor.getColumnIndex(Tables.Makers.LOCATION));
            mTxtMaker.setText(name);
            mTxtOrigin.setText(origin);

            // skip origin field
            mTxtOrigin.focusSearch(View.FOCUS_DOWN).requestFocus();
        }
    });
}