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.heske.alexandria.activities.ListOfBooksFragment.java

public String getBookAtPosition(int position) {
    Cursor cursor = (Cursor) mBookListAdapter.getItem(mLastPosition);

    if (cursor != null && cursor.moveToPosition(position)) {
        return (cursor.getString(cursor.getColumnIndex(AlexandriaContract.BookEntry._ID)));
    }/*from  w w w  . java  2  s.co m*/
    return null;
}

From source file:com.android.calendar.Event.java

/**
 * Adds all the events from the cursors to the events list.
 *
 * @param events The list of events/*from   w w w  .j av  a 2 s.c o m*/
 * @param cEvents Events to add to the list
 * @param context
 * @param startDay
 * @param endDay
 */
public static void buildEventsFromCursor(ArrayList<Event> events, Cursor cEvents, Context context, int startDay,
        int endDay) {
    if (cEvents == null || events == null) {
        Log.e(TAG, "buildEventsFromCursor: null cursor or null events list!");
        return;
    }

    int count = cEvents.getCount();

    if (count == 0) {
        return;
    }

    Resources res = context.getResources();
    mNoTitleString = res.getString(R.string.no_title_label);
    mNoColorColor = res.getColor(R.color.event_center);
    // Sort events in two passes so we ensure the allday and standard events
    // get sorted in the correct order
    cEvents.moveToPosition(-1);
    while (cEvents.moveToNext()) {
        Event e = generateEventFromCursor(cEvents);
        if (e.startDay > endDay || e.endDay < startDay) {
            continue;
        }
        events.add(e);
    }
}

From source file:com.btmura.android.reddit.app.MessageThingListController.java

@Override
public ThingBundle getThingBundle(int position) {
    Cursor c = adapter.getCursor();
    if (c != null && c.moveToPosition(position)) {
        return adapter.getThingBundle(position);
    }// w w w  . j  av  a  2 s  . c o  m
    return null;
}

From source file:com.securecomcode.text.contacts.ContactSelectionListAdapter.java

@Override
public long getHeaderId(int i) {
    final Cursor c = getCursor();
    c.moveToPosition(i);
    return c.getInt(c.getColumnIndexOrThrow(ContactsDatabase.TYPE_COLUMN));
}

From source file:org.ohmage.fragments.StreamsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    ArrayList<Stream> streams = new ArrayList<Stream>();
    data.moveToPosition(-1);
    while (data.moveToNext()) {
        Stream stream = new Stream();
        stream.read(gson, data);// w  ww  .j  a  v  a  2 s .c o m
        streams.add(stream);
    }
    getListAdapter().swapItems(ApkSet.fromStreams(streams));
    setGridShown(true);
}

From source file:net.simonvt.schematic.sample.ui.fragment.NoteFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    unbinder = ButterKnife.bind(this, view);
    LoaderManager.LoaderCallbacks<Cursor> callBack = new LoaderManager.LoaderCallbacks<Cursor>() {
        @Override/*  w w  w.j a v a2s .  c  om*/
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return new CursorLoader(getActivity(), NotesProvider.NotesTags.fromNote(noteId), null, null, null,
                    null);
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
            data.moveToPosition(-1);
            StringBuffer buffer = new StringBuffer();
            while (data.moveToNext()) {
                if (buffer.length() > 0) {
                    buffer.append(",");
                }
                buffer.append(Cursors.getString(data, TagColumns.NAME));
            }
            tags.setText(buffer.toString());
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {

        }
    };
    if (noteId != NO_ID) {
        noteView.setText(note);
        statusView.setChecked(NoteColumns.STATUS_COMPLETED.equals(status));
        actionText.setText(R.string.update);
        getLoaderManager().initLoader(1, null, callBack);
    } else {
        statusView.setChecked(false);
        actionText.setText(R.string.insert);
    }
}

From source file:ca.mudar.parkcatcher.ui.fragments.FavoritesFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Cursor c = mAdapter.getCursor();

    if ((position < 0) || (position == c.getCount())) {
        return;//  w  ww.  j  a v  a2  s.  co  m
    }

    c.moveToPosition(position);
    int idPost = c.getInt(FavoritesQuery.ID_POST);

    Intent intent = new Intent(getSherlockActivity(), DetailsActivity.class);
    intent.putExtra(Const.INTENT_EXTRA_POST_ID, idPost);
    getSherlockActivity().startActivity(intent);
}

From source file:com.example.puter.sunshine.app.ForecastFragment.java

private void openPreferredLocationInMap() {

    if (null != mForecastAdapter) {
        Cursor c = mForecastAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);/*from   ww w  .  j a va 2 s .c o  m*/
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}

From source file:edu.mit.mobile.android.livingpostcards.CardListFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final Uri item = ContentUris.withAppendedId(mCards, id);
    final Cursor c = mAdapter.getCursor();
    c.moveToPosition(position);
    if (Card.isDraft(c)) {
        startActivity(new Intent(Intent.ACTION_EDIT, item));
    } else {//from   w  ww.j  av a  2s .c  o  m
        startActivity(new Intent(Intent.ACTION_VIEW, item));
    }
}

From source file:org.onebusaway.android.ui.MyRemindersFragment.java

private String[] getIds(ListView l, int position) {
    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    final Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String[] result = new String[] { c.getString(COL_ID), c.getString(COL_STOP_ID),
            c.getString(COL_ROUTE_ID) };
    return result;
}