Example usage for android.database Cursor moveToPosition

List of usage examples for android.database Cursor moveToPosition

Introduction

In this page you can find the example usage for android.database Cursor moveToPosition.

Prototype

boolean moveToPosition(int position);

Source Link

Document

Move the cursor to an absolute position.

Usage

From source file:com.money.manager.ex.currency.list.CurrencyListFragment.java

private List<Currency> getVisibleCurrencies() {
    CurrencyListAdapter adapter = (CurrencyListAdapter) getListAdapter();
    if (adapter == null)
        return null;

    Cursor cursor = adapter.getCursor();
    if (cursor == null)
        return null;

    cursor.moveToPosition(Constants.NOT_SET);
    List<Currency> currencies = new ArrayList<>();

    while (cursor.moveToNext()) {
        Currency currency = Currency.fromCursor(cursor);
        currencies.add(currency);/*from   ww  w. j  a v  a  2  s.c  om*/
    }

    return currencies;
}

From source file:com.Sunshine.MainActivity.java

/**
 * Called when a Loader has finished loading its data.
 *
 * NOTE: There is one small bug in this code. If no data is present in the cursor do to an
 * initial load being performed with no access to internet, the loading indicator will show
 * indefinitely, until data is present from the ContentProvider. This will be fixed in a
 * future version of the course./* w  ww  .j a v a  2s .  c  o m*/
 *
 * @param loader The Loader that has finished.
 * @param data   The data generated by the Loader.
 */
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    mForecastAdapter.swapCursor(data);
    if (mPosition == RecyclerView.NO_POSITION)
        mPosition = 0;
    mRecyclerView.smoothScrollToPosition(mPosition);
    if (data.getCount() != 0)
        showWeatherDataView();

    data.moveToPosition(1);
    int high = (int) data.getDouble(data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP));
    int low = (int) data.getDouble(data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP));
    int id = data.getInt(data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID));
    Intent i = new Intent(MainActivity.this, WearableDataSync.class);
    i.putExtra("high", high);
    i.putExtra("low", low);
    i.putExtra("w_id", id);
    startService(i);
}

From source file:com.monxalo.android.widget.SectionCursorAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    int viewType = getItemViewType(position);

    if (viewType == TYPE_NORMAL) {
        Cursor c = (Cursor) getItem(position);

        if (c == null) {
            if (LOGV)
                Log.d(TAG, "getItem(" + position + ") = null");
            return mLayoutInflater.inflate(mHeaderRes, parent, false);
        }/*from  ww w  . java  2s  .c  om*/

        final int mapCursorPos = getSectionForPosition(position);
        c.moveToPosition(mapCursorPos);

        return super.getView(mapCursorPos, convertView, parent);
    } else {

        ViewHolder holder = null;

        if (convertView == null) {
            if (LOGV)
                Log.v(TAG, "Creating new view for section");

            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(mHeaderRes, parent, false);
            holder.textView = (TextView) convertView;

            convertView.setTag(holder);
        } else {
            if (LOGV)
                Log.v(TAG, "Reusing view for section");

            holder = (ViewHolder) convertView.getTag();
        }

        TextView sectionText = holder.textView;

        final String group = sectionsIndexer.get(position);
        final String customFormat = getGroupCustomFormat(group);

        sectionText.setText(customFormat == null ? group : customFormat);

        return sectionText;
    }
}

From source file:com.money.manager.ex.currency.list.CurrencyListFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    // take cursor and move to position
    Cursor cursor = ((CurrencyListAdapter) getListAdapter()).getCursor();
    cursor.moveToPosition(info.position);
    int currencyId = cursor.getInt(cursor.getColumnIndex(Currency.CURRENCYID));

    CurrencyUIFeatures ui = new CurrencyUIFeatures(getActivity());

    // check item selected
    int selectedItem = item.getItemId();
    switch (selectedItem) {
    case 0: //EDIT
        ui.startCurrencyEditActivity(currencyId);
        break;/*w ww  .j a  va2  s. c om*/

    case 1: // Chart
        // remember the device orientation and return to it after the chart.
        this.mPreviousOrientation = ActivityUtils.forceCurrentOrientation(getActivity());

        // add the currency information.
        String symbol = cursor.getString(cursor.getColumnIndex(Currency.CURRENCY_SYMBOL));
        CurrencyService currencyService = this.getService();
        String baseCurrencyCode = currencyService.getBaseCurrencyCode();

        Intent intent = new Intent(getActivity(), CurrencyChartActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.putExtra(Currency.CURRENCY_SYMBOL, symbol);
        intent.putExtra(CurrencyChartActivity.BASE_CURRENCY_SYMBOL, baseCurrencyCode);

        startActivity(intent);
        break;

    case 2: // Update exchange rate
        getService().updateExchangeRate(currencyId);
        break;

    case 3: //DELETE
        CurrencyService service = new CurrencyService(getActivity());
        boolean used = service.isCurrencyUsed(currencyId);

        if (used) {
            ui.notifyCurrencyCanNotBeDeleted();
        } else {
            ContentValues contentValues = new ContentValues();
            contentValues.put(Account.CURRENCYID, currencyId);
            ui.showDialogDeleteCurrency(currencyId, info.position);
        }
        break;
    }
    return false;
}

From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java

public void showSms(int position) {
    //SL.get(AnalyticsService.class).trackEvent("show-sms", "my-tickets");
    Cursor cursor = getCursor();
    if (cursor.isClosed()) {
        return;/*from   www .j  a v  a2s. c  o m*/
    }
    cursor.moveToPosition(position);
    String text = cursor.getString(iText);
    long cityId = cursor.getLong(iCityId);
    ShowSmsDialogFragment.newInstance(text, cityId).show(mFragment.getFragmentManager(),
            ShowSmsDialogFragment.TAG);
}

From source file:ru.orangesoftware.financisto.activity.ActivityLayout.java

public void select(Context context, final int id, int titleId, final Cursor cursor, final ListAdapter adapter,
        final String idColumn, long valueId) {
    int pos = Utils.moveCursor(cursor, idColumn, valueId);
    selectSingleChoice(context, titleId, adapter, pos, (dialog, which) -> {
        dialog.cancel();/*from  w w w.j  ava2  s.co m*/
        cursor.moveToPosition(which);
        long selectedId = cursor.getLong(cursor.getColumnIndexOrThrow(idColumn));
        listener.onSelectedId(id, selectedId);
    });
}

From source file:org.alfresco.mobile.android.application.fragments.operation.OperationsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
    super.onLoadFinished(arg0, cursor);
    if (cursor.getCount() == 0) {
        dismissAll.setVisibility(View.GONE);
        ev.setVisibility(View.VISIBLE);
        displayEmptyView();/*from  w ww  .  j  a va2 s.  co  m*/
    } else {
        dismissAll.setVisibility(View.VISIBLE);
        if (!cursor.isFirst()) {
            cursor.moveToPosition(-1);
        }

        boolean isVisible = false;
        while (cursor.moveToNext()) {
            if (cursor.getInt(OperationSchema.COLUMN_STATUS_ID) == Operation.STATUS_RUNNING
                    || cursor.getInt(OperationSchema.COLUMN_STATUS_ID) == Operation.STATUS_PENDING) {
                isVisible = true;
                break;
            }
        }

        cancelAll.setVisibility(View.GONE);
        if (isVisible) {
            cancelAll.setVisibility(View.VISIBLE);
        }
    }
    refreshHelper.setRefreshComplete();
}

From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java

private void deleteTicket(int position) {
    //SL.get(AnalyticsService.class).trackEvent("delete", "my-tickets");
    Cursor cursor = getCursor();
    if (cursor.isClosed()) {
        return;/*from  w  w  w .j  a  v  a2 s  . co m*/
    }
    cursor.moveToPosition(position);
    long id;
    try {
        id = cursor.getLong(iId);
    } catch (CursorIndexOutOfBoundsException e) {
        return;
    }
    c.getContentResolver().delete(ContentUris.withAppendedId(Tickets.CONTENT_URI, id), null, null);
    getCursor().requery();
}

From source file:org.mariotaku.twidere.adapter.ParcelableActivitiesAdapter.java

public long getTimestamp(int adapterPosition) {
    int dataPosition = adapterPosition - getActivityStartIndex();
    if (dataPosition < 0 || dataPosition >= getActivityCount())
        return RecyclerView.NO_ID;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return -1;
        final ParcelableActivityCursorIndices indices = (ParcelableActivityCursorIndices) ((ObjectCursor) mData)
                .getIndices();// w  w  w.  j av  a2 s . co m
        return cursor.getLong(indices.timestamp);
    }
    return mData.get(dataPosition).timestamp;
}

From source file:org.mariotaku.twidere.adapter.ParcelableActivitiesAdapter.java

@Nullable
public String getActivityAction(int adapterPosition) {
    int dataPosition = adapterPosition - getActivityStartIndex();
    if (dataPosition < 0 || dataPosition >= getActivityCount())
        return null;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return null;
        final ParcelableActivityCursorIndices indices = (ParcelableActivityCursorIndices) ((ObjectCursor) mData)
                .getIndices();//from www .  ja  va2 s .  c o  m
        return cursor.getString(indices.action);
    }
    return mData.get(dataPosition).action;
}