Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8328011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:18:13+00:00 2026-06-09T01:18:13+00:00

I’m using the ViewHolder pattern with a CursorAdapter to populate a ListView. I’m trying

  • 0

I’m using the ViewHolder pattern with a CursorAdapter to populate a ListView. I’m trying to store an integer in my ViewHolder that corresponds to a value in a column from my cursor. Later I want to iterate over all the items in my ListView and pull out this value.

However, it appears that when the CursorAdapter recycles my views, it doesn’t update the integer value in my ViewHolder.

Here is the relevant code in my CursorAdapter (I’m using Mono For Android, so the code is C#, but the idea is the same).

    public override void BindView(View view, Context context, ICursor cursor)
    {
        var viewHolder = view.Tag as ViewHolder;

        if (viewHolder.GroupCheckedTextView != null)
        {
            viewHolder.GroupCheckedTextView.Text = cursor.GetString(ColumnMapping["Name"]);
        }

        if (viewHolder.FieldTextView != null)
        {
            viewHolder.FieldTextView.Text = cursor.GetString(ColumnMapping["Value"]);
            viewHolder.LabelTextView.Text = cursor.GetString(ColumnMapping["Label"]) ?? cursor.GetString(ColumnMapping["TypeLabel"]);
        }

        // I tried updating it manually, but it doesn't stick...
        //viewHolder.GroupId = cursor.GetInt(ColumnMapping["GroupId"]);
        //view.Tag = viewHolder;
    }

    public override View NewView(Context context, ICursor cursor, ViewGroup parent)
    {
        var inflator = LayoutInflater.FromContext(context);
        View view = null;

        if (IsNewGroup(cursor, cursor.Position))
        {
            view = inflator.Inflate(Resource.Layout.Group, parent, false);
        }
        else
        {
            view = inflator.Inflate(Resource.Layout.Field, parent, false);
        }

        var viewHolder = new ViewHolder(view);
        viewHolder.GroupId = cursor.GetInt(ColumnMapping["GroupId"]);
        view.Tag = viewHolder;

        return view;
    }

I think I understand why. The ViewHolder pattern is more about reusing the Views so you don’t have to search for them again, but is there any way to extend it to work with what I want? The only solution I can think of is to create a hidden view and stuff this integer into it’s text field, which I can retrieve later, but I hoping there is a less hacky solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:18:16+00:00Added an answer on June 9, 2026 at 1:18 am

    The ViewHolder pattern is more about reusing the Views so you don’t
    have to search for them again, but is there any way to extend it to
    work with what I want?

    That is correct, the holder patter is used to cache looking for views each time a row needs to be shown. Maybe I didn’t understand what you’re trying to do, but following:

    I’m trying to store an integer in my ViewHolder that corresponds to a
    value in a column from my cursor. Later I want to iterate over all the
    items in my ListView and pull out this value.

    Why can’t you simple get a reference to the underlining Cursor(a CursorAdapter has the getCursor method), step over it and extract the values you want(which, after reading your code, seems to be the id of the row)? You could always store internally, in the adapter, an array/list of the desired values from cursor. This array/list will be updated in the bindView so you have the correct values in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.