List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:com.baksoy.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_TODAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getArtResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break;/*from w ww.java 2 s . c o m*/ } case VIEW_TYPE_FUTURE_DAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getIconResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break; } } // Read date from cursor long dateInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE); // Find TextView and set formatted date on it viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis)); // Read weather forecast from cursor String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC); // Find TextView and set weather forecast on it viewHolder.descriptionView.setText(description); // For accessibility, add a content description to the icon field viewHolder.iconView.setContentDescription(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); // Read high temperature from cursor double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highTempView.setText(Utility.formatTemperature(context, high)); // Read low temperature from cursor double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowTempView.setText(Utility.formatTemperature(context, low)); }
From source file:android.database.DatabaseUtils.java
/** * Prints the contents of a Cursor to a PrintSteam. The position is restored * after printing./*w w w. j a v a 2 s . c o m*/ * * @param cursor the cursor to print * @param stream the stream to print to */ public static void dumpCursor(Cursor cursor, PrintStream stream) { stream.println(">>>>> Dumping cursor " + cursor); if (cursor != null) { int startPos = cursor.getPosition(); cursor.moveToPosition(-1); while (cursor.moveToNext()) { dumpCurrentRow(cursor, stream); } cursor.moveToPosition(startPos); } stream.println("<<<<<"); }
From source file:android.database.DatabaseUtils.java
/** * Prints the contents of a Cursor to a StringBuilder. The position * is restored after printing./* w w w . java 2s . c o m*/ * * @param cursor the cursor to print * @param sb the StringBuilder to print to */ public static void dumpCursor(Cursor cursor, StringBuilder sb) { sb.append(">>>>> Dumping cursor " + cursor + "\n"); if (cursor != null) { int startPos = cursor.getPosition(); cursor.moveToPosition(-1); while (cursor.moveToNext()) { dumpCurrentRow(cursor, sb); } cursor.moveToPosition(startPos); } sb.append("<<<<<\n"); }
From source file:org.mariotaku.twidere.adapter.DirectMessagesConversationAdapter.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final int position = cursor.getPosition(); final DirectMessageConversationViewHolder holder = (DirectMessageConversationViewHolder) view.getTag(); final long account_id = cursor.getLong(mIndices.account_id); final long message_timestamp = cursor.getLong(mIndices.message_timestamp); final boolean is_outgoing = cursor.getInt(mIndices.is_outgoing) == 1; final String name = cursor.getString(mIndices.sender_name); final String screen_name = cursor.getString(mIndices.sender_screen_name); holder.setTextSize(mTextSize);//w w w . j a v a 2 s. co m switch (mNameDisplayOption) { case NAME_DISPLAY_OPTION_CODE_NAME: { holder.name.setText(name); holder.screen_name.setText(null); holder.screen_name.setVisibility(View.GONE); break; } case NAME_DISPLAY_OPTION_CODE_SCREEN_NAME: { holder.name.setText("@" + screen_name); holder.screen_name.setText(null); holder.screen_name.setVisibility(View.GONE); break; } default: { holder.name.setText(name); holder.screen_name.setText("@" + screen_name); holder.screen_name.setVisibility(View.VISIBLE); break; } } final FrameLayout.LayoutParams lp = (LayoutParams) holder.name_container.getLayoutParams(); lp.gravity = is_outgoing ? Gravity.LEFT : Gravity.RIGHT; holder.name_container.setLayoutParams(lp); holder.text.setText(Html.fromHtml(cursor.getString(mIndices.text))); final TwidereLinkify linkify = new TwidereLinkify(holder.text); linkify.setOnLinkClickListener(new OnLinkClickHandler(context, account_id)); linkify.addAllLinks(); holder.text.setMovementMethod(null); holder.text.setGravity(is_outgoing ? Gravity.LEFT : Gravity.RIGHT); holder.time.setText(formatToLongTimeString(mContext, message_timestamp)); holder.time.setGravity(is_outgoing ? Gravity.RIGHT : Gravity.LEFT); holder.profile_image_left.setVisibility(mDisplayProfileImage && is_outgoing ? View.VISIBLE : View.GONE); holder.profile_image_right.setVisibility(mDisplayProfileImage && !is_outgoing ? View.VISIBLE : View.GONE); if (mDisplayProfileImage) { final String profile_image_url_string = cursor.getString(mIndices.sender_profile_image_url); mImageLoader.displayImage(holder.profile_image_left, profile_image_url_string); mImageLoader.displayImage(holder.profile_image_right, profile_image_url_string); holder.profile_image_left.setTag(position); holder.profile_image_right.setTag(position); } super.bindView(view, context, cursor); }
From source file:com.example.talonso.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_TODAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getArtResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break;/*ww w . j ava 2 s. c om*/ } case VIEW_TYPE_FUTURE_DAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getIconResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break; } } // Read date from cursor long dateInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE); // Find TextView and set formatted date on it viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis)); // Read weather forecast from cursor String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC); // Find TextView and set weather forecast on it viewHolder.descriptionView.setText(description); // For accessibility, add a content description to the icon field viewHolder.iconView.setContentDescription(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); // Read high temperature from cursor double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highTempView.setText(Utility.formatTemperature(context, high, isMetric)); // Read low temperature from cursor double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowTempView.setText(Utility.formatTemperature(context, low, isMetric)); }
From source file:fr.eoidb.activity.util.ItemListViewBinder.java
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); numberOfElements = cursor.getCount(); currentPosition = cursor.getPosition(); switch (viewId) { case R.id.item_name: case R.id.ITEM_NAME: String value = cursor.getString(columnIndex); initName(view, value);//from w w w .jav a 2 s . c o m break; case R.id.item_icon: case R.id.ITEM_ICON: id = cursor.getLong(columnIndex); initIcon(view, id); break; default: throw new IllegalArgumentException("viewId : " + viewId); } return true; }
From source file:at.wada811.imageslider.MainActivity.java
private void initCursorLoader() { getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override/*from ww w . ja va 2 s. c o m*/ public Loader<Cursor> onCreateLoader(int id, Bundle data) { Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; return new CursorLoader(self, uri, null, null, null, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { mCursor = cursor; LogUtils.d("Position: " + cursor.getPosition()); boolean moveToFirst = cursor.moveToFirst(); LogUtils.d("moveToFirst: " + moveToFirst); LogUtils.d("Position: " + cursor.getPosition()); Bitmap bitmap = loadBitmap(cursor); mImageSliderFragment.setImageBitmap(bitmap); } @Override public void onLoaderReset(Loader<Cursor> loader) { } }); }
From source file:com.example.asadkhan.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_TODAY: { viewHolder.iconView.setImageResource(Utility.getArtResourceForWeatherCondition( cursor.getInt(MainForecastFragment.COL_WEATHER_CONDITION_ID))); break;/*from w w w. j a v a 2 s. c om*/ } case VIEW_TYPE_FUTURE_DAY: { viewHolder.iconView.setImageResource(Utility.getIconResourceForWeatherCondition( cursor.getInt(MainForecastFragment.COL_WEATHER_CONDITION_ID))); break; } } Long dateInMillis = cursor.getLong(MainForecastFragment.COL_WEATHER_DATE); viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis)); String description = cursor.getString(MainForecastFragment.COL_WEATHER_DESC); viewHolder.descriptionView.setText(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); double high = cursor.getDouble(MainForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highTempView.setText(Utility.formatTemperature(context, high, isMetric)); double low = cursor.getDouble(MainForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowTempView.setText(Utility.formatTemperature(context, low, isMetric)); // Log.e(LOG_TAG, "High val : " + high); // Log.e(LOG_TAG, "Low val : " + low); }
From source file:com.rsegismont.androlife.programlist.FragmentListProgrammes.java
public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong) { if (SdkUtils.isTabletLandscape(getActivity())) { ((ProgramListActivity) getActivity()).setDetailsSelection(paramInt); } else {/*from w w w . j a v a 2 s. c o m*/ Cursor localCursor = getCursor(); int i = localCursor.getPosition(); localCursor.moveToPosition(paramInt); int j = localCursor.getColumnIndex(SharedInformation.DatabaseColumn.DATE_UTC.stringValue); Intent localIntent = new Intent(getActivity(), ProgrammesDetailActivity.class); localIntent.putExtra(Constantes.DETAIL_DATE_TIME, localCursor.getLong(j)); localIntent.putExtra(Constantes.TYPE, this.mType); if (i >= 0) localCursor.moveToPosition(i); startActivity(localIntent); } }
From source file:org.uab.deic.uabdroid.adapters.ExpandableMaterialsAdapter.java
@Override protected Cursor getChildrenCursor(Cursor _groupCursor) { Loader<Cursor> loader = mLoaderManager.getLoader(1); if (loader == null) { Bundle arguments = new Bundle(); arguments.putInt(CHILD_POSITION_KEY, _groupCursor.getPosition()); mLoadersCounter++;//from w ww.j a va 2 s . c o m mLoaderManager.initLoader(mLoadersCounter, arguments, new MaterialsAdapterCallback()); } else { loader.forceLoad(); } return null; }