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.example.joeroger.homework2.activity.WeatherActivity.java

private void updateSelectionValues(int position) {
    selectedPos = position;/*from  w w  w.  jav a 2s . co  m*/
    Cursor cursor = citySpinnerCursorAdapter.getCursor();
    cursor.moveToPosition(position);
    selectedCity = cursor.getLong(CITY_ID_POS);
    isSelectedFavorite = cursor.getInt(FAVORITE_POS) == 1;
}

From source file:com.battlelancer.seriesguide.adapters.EpisodesAdapter.java

/**
 * Get the item position in the data set, or the position of the first item if it is not found.
 *//*w  w  w . j ava2 s  .c o  m*/
public int getItemPosition(long itemId) {
    Cursor cursor = getCursor();
    if (cursor != null) {
        int rowId = cursor.getColumnIndexOrThrow("_id");
        for (int position = 0; position < cursor.getCount(); position++) {
            if (!cursor.moveToPosition(position)) {
                return 0;
            }
            if (cursor.getLong(rowId) == itemId) {
                return position;
            }
        }
    }

    return 0;
}

From source file:com.silentcircle.contacts.group.GroupDetailFragment.java

private void bindGroupMetaData(Cursor cursor) {
    cursor.moveToPosition(-1);
    if (cursor.moveToNext()) {
        mGroupId = cursor.getLong(GroupMetaDataLoader.GROUP_ID);
        mGroupName = cursor.getString(GroupMetaDataLoader.TITLE);
        mIsReadOnly = cursor.getInt(GroupMetaDataLoader.IS_READ_ONLY) == 1;
        updateTitle(mGroupName);//from w  w  w .  java 2  s .  c om
        // Must call invalidate so that the option menu will get updated
        getActivity().supportInvalidateOptionsMenu();
    }
}

From source file:org.bwgz.quotation.fragment.BookmarkAuthorsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    Log.d(TAG, String.format("onCreateView - this: %s  inflater: %s  container: %s  savedInstanceState: %s",
            this, inflater, container, savedInstanceState));
    View view = inflater.inflate(R.layout.standard_list_view, container, false);

    ListView listView = (ListView) view.findViewById(R.id.list_view);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from  w w w  .  j  a  va2 s  . com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, String.format("onItemClick - parent: %s  view: %s  position: %d  id: %d", parent, view,
                    position, id));
            List<String> ids = new ArrayList<String>();

            Cursor cursor = (Cursor) adapter.getItem(position);
            Log.d(TAG, String.format("onItemClick - authorId: %s",
                    cursor.getString(cursor.getColumnIndex(Person._ID))));

            for (int i = 0; i < cursor.getCount(); i++) {
                cursor.moveToPosition(i);
                ids.add(cursor.getString(cursor.getColumnIndex(Person._ID)));
            }

            Intent intent = new Intent(view.getContext(), AuthorActivity.class);
            intent.putExtra(PickViewPagerActivity.EXTRA_IDS, ids.toArray(new String[ids.size()]));
            intent.putExtra(PickViewPagerActivity.EXTRA_POSITION, position);

            view.getContext().startActivity(intent);
        }
    });

    initLoader(
            this, BookmarkPerson.CONTENT_URI, new String[] { Person.FULL_ID, Person.NAME, Person.DESCRIPTION,
                    Person.NOTABLE_FOR, Person.IMAGE_ID, Person.QUOTATION_COUNT, BookmarkPerson.BOOKMARK_ID },
            null, null, null);

    return view;
}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    JasperMobileApplication.removeAllCookies();

    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);

    JsServerProfile oldProfile = jsRestClient.getServerProfile();
    long profileId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID));

    boolean isSameCurrentProfileSelected = (oldProfile != null && oldProfile.getId() == profileId);

    if (isSameCurrentProfileSelected) {
        setResultOk(profileId);//from   w w  w.  ja va2s  .  c o  m
    } else {
        JsServerProfile newProfile = profileHelper.createProfileFromCursor(cursor);
        String password = newProfile.getPassword();

        boolean alwaysAskPassword = TextUtils.isEmpty(password);
        if (alwaysAskPassword) {
            setResultOk(profileId);
        } else {
            JsRestClient tmpRestClient = new JsRestClient();
            tmpRestClient.setConnectTimeout(prefHelper.getConnectTimeoutValue());
            tmpRestClient.setReadTimeout(prefHelper.getReadTimeoutValue());
            tmpRestClient.setServerProfile(newProfile);

            GetServerInfoRequest request = new GetServerInfoRequest(tmpRestClient);
            request.setRetryPolicy(null);

            setRefreshActionState(true);
            getSpiceManager().execute(new GetServerInfoRequest(tmpRestClient),
                    new ValidateServerInfoListener(newProfile));
        }
    }
}

From source file:com.chrismorais.android.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);/*w  w  w.j  av  a 2s.  c om*/
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}

From source file:de.vanita5.twittnuker.activity.support.DraftsActivity.java

@Override
public void onItemClick(final AdapterView<?> view, final View child, final int position, final long id) {
    final Cursor c = mAdapter.getCursor();
    if (c == null || c.isClosed() || !c.moveToPosition(position))
        return;//w  w  w . j ava2s  .c  om
    final DraftItem item = new DraftItem(c, new DraftItem.CursorIndices(c));
    if (item.action_type == Drafts.ACTION_UPDATE_STATUS || item.action_type <= 0) {
        editDraft(item);
    }
}

From source file:com.rowland.hashtrace.ui.fragments.subfragment.FavouriteListFragment.java

@Override
public void onListItemClick(ListView lv, View view, int position, long rowID) {
    super.onListItemClick(lv, view, position, rowID);
    // Do the onItemClick action
    Cursor cursor = mTweetFavListAdapter.getCursor();
    if (cursor != null && cursor.moveToPosition(position)) {
        ((onFavouriteItemSelectedCallback) getActivity()).onFavouriteItemSelected((int) rowID);
    }//from  ww  w .jav a 2 s .c om
    mPosition = position;
    Log.d("ROWSELECT", "" + rowID);
}

From source file:com.aniruddhc.acemusic.player.Dialogs.EQGenresListDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mApp = (Common) getActivity().getApplicationContext();
    mEqualizerFragment = (EqualizerActivity) getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Get a cursor with the list of all the unique genres.
    final Cursor cursor = mApp.getDBAccessHelper().getAllUniqueGenres("");

    //Set the dialog title.
    builder.setTitle(R.string.apply_to);
    builder.setCursor(cursor, new DialogInterface.OnClickListener() {

        @Override//from  w  ww  .j  ava 2 s.  com
        public void onClick(DialogInterface dialog, int which) {
            cursor.moveToPosition(which);
            String genreName = cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_GENRE));
            AsyncApplyEQToGenreTask task = new AsyncApplyEQToGenreTask(getActivity(), genreName,
                    mEqualizerFragment.getFiftyHertzLevel(), mEqualizerFragment.getOneThirtyHertzLevel(),
                    mEqualizerFragment.getThreeTwentyHertzLevel(),
                    mEqualizerFragment.getEightHundredHertzLevel(), mEqualizerFragment.getTwoKilohertzLevel(),
                    mEqualizerFragment.getFiveKilohertzLevel(),
                    mEqualizerFragment.getTwelvePointFiveKilohertzLevel(),
                    (short) mEqualizerFragment.getVirtualizerSeekBar().getProgress(),
                    (short) mEqualizerFragment.getBassBoostSeekBar().getProgress(),
                    (short) mEqualizerFragment.getReverbSpinner().getSelectedItemPosition());

            task.execute(new String[] { "" + which });

            if (cursor != null)
                cursor.close();

            //Hide the equalizer fragment.
            getActivity().finish();

        }

    }, DBAccessHelper.SONG_GENRE);

    return builder.create();
}

From source file:com.aniruddhc.acemusic.player.Dialogs.EQAlbumsListDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mApp = (Common) getActivity().getApplicationContext();
    mEqualizerFragment = (EqualizerActivity) getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Get a cursor with the list of all albums.
    final Cursor cursor = mApp.getDBAccessHelper().getAllAlbumsOrderByName();

    //Set the dialog title.
    builder.setTitle(R.string.apply_to);
    builder.setCursor(cursor, new DialogInterface.OnClickListener() {

        @Override/*from   w w w  . j  a  v a2s  .  com*/
        public void onClick(DialogInterface dialog, int which) {
            cursor.moveToPosition(which);
            String albumName = cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ALBUM));
            AsyncApplyEQToAlbumTask task = new AsyncApplyEQToAlbumTask(getActivity(), albumName,
                    mEqualizerFragment.getFiftyHertzLevel(), mEqualizerFragment.getOneThirtyHertzLevel(),
                    mEqualizerFragment.getThreeTwentyHertzLevel(),
                    mEqualizerFragment.getEightHundredHertzLevel(), mEqualizerFragment.getTwoKilohertzLevel(),
                    mEqualizerFragment.getFiveKilohertzLevel(),
                    mEqualizerFragment.getTwelvePointFiveKilohertzLevel(),
                    (short) mEqualizerFragment.getVirtualizerSeekBar().getProgress(),
                    (short) mEqualizerFragment.getBassBoostSeekBar().getProgress(),
                    (short) mEqualizerFragment.getReverbSpinner().getSelectedItemPosition());

            task.execute(new String[] { "" + which });

            if (cursor != null)
                cursor.close();

            //Hide the equalizer fragment.
            getActivity().finish();

        }

    }, DBAccessHelper.SONG_ALBUM);

    return builder.create();
}