List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:com.aniruddhc.acemusic.player.Dialogs.EQArtistsListDialog.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 artists. final Cursor cursor = mApp.getDBAccessHelper().getAllArtistsOrderByName(); //Set the dialog title. builder.setTitle(R.string.apply_to); builder.setCursor(cursor, new DialogInterface.OnClickListener() { @Override//from ww w .j a v a 2s .c o m public void onClick(DialogInterface dialog, int which) { cursor.moveToPosition(which); String songArtist = cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)); AsyncApplyEQToArtistTask task = new AsyncApplyEQToArtistTask(getActivity(), songArtist, 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_ARTIST); return builder.create(); }
From source file:com.github.monxalo.android.widget.SectionCursorAdapter.java
private void calculateSectionHeaders() { int i = 0;/*ww w. ja v a 2s.c o m*/ String previous = ""; int count = 0; final Cursor c = getCursor(); mSectionsIndexer.clear(); if (c == null || c.isClosed()) { return; } c.moveToPosition(-1); while (c.moveToNext()) { final String group = getCustomGroup(c); if (!previous.equals(group)) { mSectionsIndexer.put(i + count, group); previous = group; if (LOGV) Log.v(TAG, "Group " + group + "at position: " + (i + count)); count++; } i++; } }
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(); } }); }
From source file:com.rowland.hashtrace.ui.fragments.SearchFragment.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 = mTweetListAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((onTweetItemSelectedCallback) getActivity()).onTweetItemSelected((int) rowID); }/*from w w w . ja v a 2 s.c o m*/ mPosition = position; Log.d("ROWSELECT", "" + rowID); }
From source file:org.mozilla.mozstumbler.service.sync.UploadReports.java
private void increaseRetryCounter(Cursor cursor, SyncResult result) { ArrayList<String> idsToDelete = new ArrayList<String>(); Map<String, String> idAndValuesToUpdate = new HashMap<String, String>(); cursor.moveToPosition(-1); int columnId = cursor.getColumnIndex(DatabaseContract.Reports._ID); int columnRetry = cursor.getColumnIndex(DatabaseContract.Reports.RETRY_NUMBER); while (cursor.moveToNext()) { int retry = cursor.getInt(columnRetry) + 1; if (retry >= MAX_RETRY_COUNT) { idsToDelete.add(cursor.getString(columnId)); } else {// ww w. jav a2 s . c o m idAndValuesToUpdate.put(cursor.getString(columnId), "" + retry); } } mContentResolver.bulkDelete(DatabaseContract.Reports.CONTENT_URI, idsToDelete); mContentResolver.bulkUpdateOneColumn(DatabaseContract.Reports.CONTENT_URI, DatabaseContract.Reports.RETRY_NUMBER, idAndValuesToUpdate); result.stats.numDeletes += idsToDelete.size(); result.stats.numUpdates += idAndValuesToUpdate.size(); }
From source file:com.katamaditya.apps.weather4u.WeatherForecastFragment.java
private void openPreferredLocationInMap() { // Using the URI scheme for showing a location found on a map. This super-handy // intent can is detailed in the "Common Intents" page of Android's developer site: // http://developer.android.com/guide/components/intents-common.html#Maps if (null != mWeatherForecastAdapter) { Cursor c = mWeatherForecastAdapter.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);/* ww w.j a v a 2s . c o m*/ } /*else { Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); }*/ } } }
From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Cursor c = mAdapter.getCursor(); c.moveToPosition(mAdapter.getCursorPosition(position)); final Intent intent = new Intent(INTENT_ACTION_EDIT_TAB); intent.setClass(getActivity(), CustomTabEditorActivity.class); intent.putExtra(EXTRA_ID, c.getLong(c.getColumnIndex(Tabs._ID))); intent.putExtra(EXTRA_TYPE, c.getString(c.getColumnIndex(Tabs.TYPE))); intent.putExtra(EXTRA_NAME, c.getString(c.getColumnIndex(Tabs.NAME))); intent.putExtra(EXTRA_ICON, c.getString(c.getColumnIndex(Tabs.ICON))); intent.putExtra(EXTRA_EXTRAS, c.getString(c.getColumnIndex(Tabs.EXTRAS))); startActivityForResult(intent, REQUEST_EDIT_TAB); }
From source file:tw.idv.palatis.danboorugallery.siteapi.GelbooruAPI.java
@Override public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) { String[] tags;/*from www . ja v a 2 s . co m*/ if (tags_cursor != null) { tags_cursor.moveToPosition(-1); tags = new String[tags_cursor.getCount()]; while (tags_cursor.moveToNext()) tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME); } else tags = new String[0]; return new GelbooruPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT), new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)), new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)), post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE), post_cursor.getString(PostsTable.INDEX_POST_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags, post_cursor.getString(PostsTable.INDEX_POST_RATING), post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO)); }
From source file:tw.idv.palatis.danboorugallery.siteapi.MoebooruAPI.java
@Override public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) { String[] tags;// w w w .j a v a2 s . c om if (tags_cursor != null) { tags_cursor.moveToPosition(-1); tags = new String[tags_cursor.getCount()]; while (tags_cursor.moveToNext()) tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME); } else tags = new String[0]; return new MoebooruPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT), new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)), new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)), post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE), post_cursor.getString(PostsTable.INDEX_POST_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags, post_cursor.getString(PostsTable.INDEX_POST_RATING), post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO)); }
From source file:com.glandorf1.joe.wsprnetviewer.app.WsprFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and // use it to populate the ListView it's attached to. mWsprAdapter = new WsprAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the grid/call header mTVGridCallHeader = (TextView) rootView.findViewById(R.id.textview_list_header_gridsquare); // Get a reference to the ListView, and attach this adapter to it. mListView = (ListView) rootView.findViewById(R.id.listview_wspr); mListView.setAdapter(mWsprAdapter);//from w w w. j a v a2 s .co m mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mWsprAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WSPR_ID)); // TODO: change to record ID!! } mPosition = position; } }); // Get previously-selected position from bundle, restore list selection during onLoadFinished. if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { mPosition = savedInstanceState.getInt(SELECTED_KEY); } mWsprAdapter.setUseDualPane(mDualPane); return rootView; }