List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:net.potterpcs.recipebook.RecipeData.java
public String[] getRecipeIngredientStrings(long rid) { Cursor c = getRecipeIngredients(rid); String[] ings = new String[c.getCount()]; c.moveToFirst();/* w w w. ja va 2s . c o m*/ while (!c.isAfterLast()) { ings[c.getPosition()] = c.getString(c.getColumnIndex(IT_NAME)); c.moveToNext(); } c.close(); return ings; }
From source file:net.potterpcs.recipebook.RecipeData.java
public String[] getRecipeDirectionStrings(long rid) { // NOTE: the returned array is in database sequential order Cursor c = getRecipeDirections(rid); String[] dirs = new String[c.getCount()]; c.moveToFirst();//from w ww . ja v a 2 s. c om while (!c.isAfterLast()) { dirs[c.getPosition()] = c.getString(c.getColumnIndex(DT_STEP)); c.moveToNext(); } c.close(); return dirs; }
From source file:net.potterpcs.recipebook.RecipeData.java
private String[] getRecipeDirectionPhotoStrings(long rid) { // NOTE: the returned array is in database sequential order Cursor c = getRecipeDirections(rid); String[] dirs = new String[c.getCount()]; c.moveToFirst();//from w w w.j a v a 2 s. c o m while (!c.isAfterLast()) { dirs[c.getPosition()] = c.getString(c.getColumnIndex(DT_PHOTO)); c.moveToNext(); } c.close(); return dirs; }
From source file:com.appjma.appdeployer.adapter.AppVersionsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); String version = cursor.getString(PROJECTION_VERSION); long updatedAt = cursor.getLong(PROJECTION_UPDATED_AT); long id = cursor.getLong(PROJECTION_APP_VERSION_ID); String downloadManagerId = cursor.getString(PROJECTION_DOWNLOAD_MANAGER_ID); int status = -1; if (downloadManagerId != null) { DownloadItem downloadItem = mMap.get(downloadManagerId); if (downloadItem != null) { status = downloadItem.mStatus; }/* www .j av a2 s . co m*/ } if (status == DownloadManager.STATUS_PENDING || status == DownloadManager.STATUS_RUNNING) { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_downloading); } else if (status == DownloadManager.STATUS_SUCCESSFUL) { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_downloaded); } else { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_download); } holder.mPosition = cursor.getPosition(); holder.mText1.setText(String.format(mVersionFormat, version)); CharSequence updatedAtText = DateUtils.getRelativeTimeSpanString(updatedAt, mNow, DateUtils.MINUTE_IN_MILLIS); holder.mText2.setText(updatedAtText); holder.mId = id; }
From source file:com.jbirdvegas.mgerrit.PatchSetViewerActivity.java
@Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { /* Weird behaviour: This method gets called multiple times. Once after * initialising this activity and starting the loader, then again later without * manually resetting the loaders. If the current tab is set we have been here, * so we don't need to find the page again. *//from ww w. jav a 2s .c om * Note: We could respond to the database being updated here (this is the only * logical reason explaining the above), but this is called too frequently, * so we will only update this when the user opens the activity */ int pos = 0; mCursor = cursor; sChangeIdIndex = cursor.getColumnIndex(UserChanges.C_CHANGE_ID); sChangeNumberIndex = cursor.getColumnIndex(UserChanges.C_COMMIT_NUMBER); while (cursor.moveToNext()) { if (cursor.getString(sChangeIdIndex).equals(mChangeId)) { pos = cursor.getPosition(); break; } } mAdapter.notifyDataSetChanged(); if (pos == mViewPager.getCurrentItem()) mCurrentTab = pos; else if (mCurrentTab == null) { mCurrentTab = pos; if (mCurrentTab >= 0) mViewPager.setCurrentItem(mCurrentTab); onNewChangeSelected(mCurrentTab); } }
From source file:com.example.amit.tellymoviebuzzz.PopularSeriesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new PopularSeriesAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.popularseries_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_popular_series); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w ww. java 2s . c o m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "upcoming"; Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); Intent intent = new Intent(getActivity(), DetailActivity.class).setData( MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, "87101")); startActivity(intent); } } }); return rootView; }
From source file:com.granita.tasks.TaskListFragment.java
/** Returns the position of the task in the cursor. Returns -1 if the task is not in the cursor **/ private int getSelectedChildPostion(Uri taskUri, Cursor listCursor) { if (taskUri != null && listCursor != null && listCursor.moveToFirst()) { Long taskIdToSelect = Long.valueOf(taskUri.getLastPathSegment()); do {//from w w w .java2 s. c o m Long taskId = listCursor.getLong(listCursor.getColumnIndex(Tasks._ID)); if (taskId.equals(taskIdToSelect)) { return listCursor.getPosition(); } } while (listCursor.moveToNext()); } return -1; }
From source file:net.abcdroid.devfest12.ui.MyScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null) { return;/*from www . j a v a2 s . c o m*/ } long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDay(previousBlockStart, blockStart)) { sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY))); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this // block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.changeCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.LoginFragment.java
/** * Add the loaded accounts into the accounts adapter when done loading from the db * @param loader the accounts loader attached to the spinner * @param data the loaded data/*from w w w . j av a2 s. c o m*/ */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // populate the adapter with the loaded accounts mAccountsAdapter.swapCursor(data); // get the id of previously selected account from the shared preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); int accountId = settings.getInt(getContext().getString(R.string.sharedpreferences_key_account_id), -1); if (accountId != -1) { // update selected account id member var mSelectedAccountId = accountId; // select the account in the spinner dropdown if (data.moveToFirst()) { while (!data.isAfterLast()) { if (data.getLong( data.getColumnIndex(MakkelijkeMarktProvider.Account.COL_ID)) == mSelectedAccountId) { mAccount.setSelection(data.getPosition()); break; } data.moveToNext(); } } } }
From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null || cursor == null) { return;/*from w w w . j a v a 2 s. c om*/ } long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDay(previousBlockStart, blockStart)) { sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY))); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this // block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.changeCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }