Example usage for android.database Cursor getPosition

List of usage examples for android.database Cursor getPosition

Introduction

In this page you can find the example usage for android.database Cursor getPosition.

Prototype

int getPosition();

Source Link

Document

Returns the current position of the cursor in the row set.

Usage

From source file:android.database.DatabaseUtils.java

/**
 * Prints the contents of a Cursor's current row to a StringBuilder.
 *
 * @param cursor the cursor to print// www .j  a  v  a  2  s  .  c o m
 * @param sb the StringBuilder to print to
 */
public static void dumpCurrentRow(Cursor cursor, StringBuilder sb) {
    String[] cols = cursor.getColumnNames();
    sb.append("" + cursor.getPosition() + " {\n");
    int length = cols.length;
    for (int i = 0; i < length; i++) {
        String value;
        try {
            value = cursor.getString(i);
        } catch (SQLiteException e) {
            // assume that if the getString threw this exception then the column is not
            // representable by a string, e.g. it is a BLOB.
            value = "<unprintable>";
        }
        sb.append("   " + cols[i] + '=' + value + "\n");
    }
    sb.append("}\n");
}

From source file:com.baksoy.sunshine.ForecastAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    // Choose the layout type
    int viewType = getItemViewType(cursor.getPosition());
    int layoutId = -1;
    switch (viewType) {
    case VIEW_TYPE_TODAY: {
        layoutId = R.layout.list_item_forecast_today;
        break;//from  ww  w.j a  va 2 s  .c o  m
    }
    case VIEW_TYPE_FUTURE_DAY: {
        layoutId = R.layout.list_item_forecast;
        break;
    }
    }

    View view = LayoutInflater.from(context).inflate(layoutId, parent, false);

    ViewHolder viewHolder = new ViewHolder(view);
    view.setTag(viewHolder);

    return view;
}

From source file:android.database.DatabaseUtils.java

/**
 * Prints the contents of a Cursor's current row to a PrintSteam.
 *
 * @param cursor the cursor to print/*from  w w w . ja  va 2s  .c om*/
 * @param stream the stream to print to
 */
public static void dumpCurrentRow(Cursor cursor, PrintStream stream) {
    String[] cols = cursor.getColumnNames();
    stream.println("" + cursor.getPosition() + " {");
    int length = cols.length;
    for (int i = 0; i < length; i++) {
        String value;
        try {
            value = cursor.getString(i);
        } catch (SQLiteException e) {
            // assume that if the getString threw this exception then the column is not
            // representable by a string, e.g. it is a BLOB.
            value = "<unprintable>";
        }
        stream.println("   " + cols[i] + '=' + value);
    }
    stream.println("}");
}

From source file:com.example.xyzreader.ui.articlelist.ArticleListAdapter.java

@Override
public void onBindViewHolder(final ViewHolder viewHolder, Cursor cursor) {

    // set up the animation per the xml files
    int position = cursor.getPosition();
    Animation animation = AnimationUtils.loadAnimation(mContext,
            (position > mLastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
    viewHolder.itemView.startAnimation(animation);
    mLastPosition = position;/*from ww w  .ja  va  2 s  .  c  om*/

    //show the thumb image (with progress spinner) or the "not found" image
    viewHolder.mArticleListImageProgressBar.setVisibility(View.VISIBLE);
    Picasso.with(mContext).load(cursor.getString(ArticleLoader.Query.THUMB_URL))
            .into(viewHolder.mArticleListImageView, new Callback() {
                @Override
                public void onSuccess() {
                    viewHolder.mArticleListImageProgressBar.setVisibility(View.GONE);
                }

                @Override
                public void onError() {
                    viewHolder.mArticleListImageView.setImageResource(R.mipmap.ic_launcher);
                }
            });

    // show the title and byline
    viewHolder.mArticleListItemTitle.setText(cursor.getString(ArticleLoader.Query.TITLE));
    String byLine = DateUtils
            .getRelativeTimeSpanString(cursor.getLong(ArticleLoader.Query.PUBLISHED_DATE),
                    System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL)
            .toString() + " by " + cursor.getString(ArticleLoader.Query.AUTHOR);
    viewHolder.mArticleListItemByLine.setText(byLine);
}

From source file:fr.mixit.android.ui.adapters.MyPlanningAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final PlanningViewHolder holder = (PlanningViewHolder) view.getTag();

    if (cursor != null) {
        final int oldPosition = cursor.getPosition();
        final long start = cursor.getLong(MixItContract.Sessions.PROJ_PLANNING.START);
        final String header = (String) DateUtils.formatPlanningHeader(start);

        long oldStart = 0;
        String oldHeader = null;//from www .  java2 s . c  o  m
        if (cursor.moveToPrevious()) {
            oldStart = cursor.getLong(MixItContract.Sessions.PROJ_PLANNING.START);
            oldHeader = (String) DateUtils.formatPlanningHeader(oldStart);
        }

        if (header.equalsIgnoreCase(oldHeader)) {
            holder.mHeader.setVisibility(View.GONE);
        } else {
            holder.mHeader.setVisibility(View.VISIBLE);
            holder.mHeader.setText(header);
        }

        cursor.moveToPosition(oldPosition);
    }

    holder.mTalk.setContentPlanning(cursor, mDisplayPastSessionsInGrey);
}

From source file:com.example.asadkhan.sunshine.ForecastAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {

    int viewType = getItemViewType(cursor.getPosition());
    int layoutId = -1;

    switch (viewType) {
    case VIEW_TYPE_TODAY: {
        layoutId = R.layout.list_item_forecast_today;

        break;/* w w w  .  j  a  v a 2 s  . com*/
    }
    case VIEW_TYPE_FUTURE_DAY: {
        layoutId = R.layout.list_item_forecast;
        break;
    }
    }

    View view = LayoutInflater.from(context).inflate(layoutId, parent, false);

    ViewHolder viewHolder = new ViewHolder(view);
    view.setTag(viewHolder);

    return view;
}

From source file:com.dwdesign.tweetings.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 long sender_id = cursor.getLong(mIndices.sender_id);

    final boolean is_outgoing = account_id == sender_id;

    final String name = mDisplayName ? cursor.getString(mIndices.sender_name)
            : cursor.getString(mIndices.sender_screen_name);

    holder.setTextSize(mTextSize);//from   www  .  j  a v a  2s . com
    final TwidereLinkify linkify = new TwidereLinkify(holder.text);
    linkify.setOnLinkClickListener(new OnLinkClickHandler(context, account_id));
    linkify.addAllLinks();
    holder.text.setMovementMethod(null);
    holder.name.setText(name);
    holder.name.setGravity(is_outgoing ? Gravity.LEFT : Gravity.RIGHT);
    holder.text.setText(cursor.getString(mIndices.text));
    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 sender_profile_image_url_string = cursor.getString(mIndices.sender_profile_image_url);
        final URL sender_profile_image_url = parseURL(
                mDisplayHiResProfileImage ? getBiggerTwitterProfileImage(sender_profile_image_url_string)
                        : sender_profile_image_url_string);

        mImageLoader.displayProfileImage(holder.profile_image_left, String.valueOf(sender_profile_image_url));
        mImageLoader.displayProfileImage(holder.profile_image_right, String.valueOf(sender_profile_image_url));
        holder.profile_image_left.setTag(position);
        holder.profile_image_right.setTag(position);
    }

    super.bindView(view, context, cursor);
}

From source file:com.dabay6.libraries.androidshared.adapters.BaseCheckableCursorAdapter.java

/**
 * {@inheritDoc}/*from   w ww .  j a  v a 2 s .  co  m*/
 */
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    final int position = cursor.getPosition();

    helper.initializeView(position, view);

    populateData(context, view, cursor);
}

From source file:nintao.com.android.study.sunshine.ForecastAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {

    //choose layout type
    int viewType = getItemViewType(cursor.getPosition());
    int layoutId = 0;
    //determine the layoutId from viewType;
    if (viewType == VIEW_TYPE_TODAY) {
        layoutId = R.layout.list_item_forecast_today;
    } else if (viewType == VIEW_TYPE_FUTURE_DAY) {
        layoutId = R.layout.list_item_forecast;
    } else {//from   www . ja  v a2 s . c  o  m
        Log.w(LOG_TAG, "Didn't match any list item view.");
    }
    //inflate the corresponding layout
    View view = LayoutInflater.from(context).inflate(layoutId, parent, false);
    ViewHolder viewHolder = new ViewHolder(view);
    view.setTag(viewHolder);

    return view;
}

From source file:org.adaway.util.CheckboxCursorAdapter.java

/**
 * Bind cursor to view using the checkboxes
 *//*from w w  w. ja v  a 2s.  c o  m*/
@Override
public void bindView(View v, Context context, Cursor cursor) {
    CheckBox cBox = (CheckBox) v.findViewById(R.id.checkbox_list_checkbox);
    if (cBox != null) {
        // bind cursor position to tag of list item
        int cursorPosition = cursor.getPosition();
        cBox.setTag(cursorPosition);

        // can also be used for Blacklist
        int enabledCol = cursor.getColumnIndexOrThrow(Whitelist.ENABLED);
        String enabled = cursor.getString(enabledCol);

        if (Integer.parseInt(enabled) == 1) {
            cBox.setChecked(true);
        } else {
            cBox.setChecked(false);
        }

        // can also be used for Blacklist
        int hostnameCol = cursor.getColumnIndexOrThrow(Blacklist.HOSTNAME);
        String hostname = cursor.getString(hostnameCol);

        cBox.setText(hostname);
    }
}