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 9226577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:51:54+00:00 2026-06-18T04:51:54+00:00

I have a list view populated by an array adapter following the ViewHolder pattern.

  • 0

I have a list view populated by an array adapter following the ViewHolder pattern. Each row is fairly complex when someone clicks a button I want to increment a count displayed in that row as well as update a string of text in that row.

So far I have everything being populated correctly but when i click a button on one cell it changes the values on the next row as well if it has been created.

I’ve tried notifyDataSetChanged() but this repopulates the whole list, which is not ideal for my case.

since I’m defining my onClick() methods within the array adapter I have a RowHolder class that holds the row v as well as the item populating that row MainListItemof the list item.

class RowHolder{
    View v;
    MainListItem i;
    RowHolder(View v, MainListItem i){
        this.v = v;
        this.i=i;
    }
}

Here is a snippet from the onClick() of the button where h is the holder

    h.loveButton.setBackgroundColor(Color.parseColor(rowHolder.i.brandLoveColor));
    h.loveButton.setImageResource(R.drawable.lovewhite);
    ((ImageView)rowHolder.v.findViewById(R.id.lovebutton)).setImageResource(R.drawable.lovewhite);              
    rowHolder.v.findViewById(R.id.lovebutton).setBackgroundColor(Color.parseColor(rowHolder.i.brandLoveColor));
    String newLovers = getLoverString(rowHolder.i,rowHolder);
    h.lovers.setText(newLovers);
    ((TextView)rowHolder.v.findViewById(R.id.lovers)).setText(newLovers);
    rowHolder.i.loverString = newLovers;
    rowHolder.i.loved = true;
    int tmp = rowHolder.i.loves
    tmp = tmp + 1;
    ((TextView)rowHolder.v.findViewById(R.id.lovecount)).setText(String.valueOf(tmp));
    h.lovecount.setText(String.valueOf(tmp));
    rowHolder.i.loves = tmp;

When the button is clicked I change the value In the data supplying the listview as well as the data in the holder holding the view as well as the data displayed in the actual view.

This implementation works fairly well except for the fact that when I change the value in the actual view it ends up changing it for all visible rows.

If someone could help me figure out a better way to accomplish this it would be great.

  • 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-18T04:51:55+00:00Added an answer on June 18, 2026 at 4:51 am

    I’ve tried notifyDataSetChanged() but this repopulates the whole list, which is not ideal for my case.

    This is one problem you need to solve. The views simply show the data. It is up to you to implement an adapter that is fast at refreshing the data. For example if you load bitmaps, then then cache them for later. Sure the first load may take time, but the second time can be instant.

    I have a RowHolder class that holds the row v as well as the item populating that row MainListItemof the list item.

    Tying the item and the row together like this is not ideal. Android recycles the views which makes this difficult to keep straight. As you have found. I have found that the settag method for a view is very handy to deal with problems like this. If a view needs to know what item in the adapter it is associated with use setTag to track that. The adapter’s getView method is a perfect place to set this. I would remove the holder altogether from the design. Try to have very few places where the data is tied to the views.

    Once you have separated the data from the view and made the adapter refresh fast. You only need to update the data and the everything else just works.

    For more info read up on the Model-View-Controller Design pattern.

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

Sidebar

Related Questions

I have created a Custom Array Adapter to populate the List View and when
I have a list view that is populated from an array of items names.
I have used a custom array adapter to populate my list view.The problem i
I have list view and its adapter stored as global variables. I am not
I have a ListView with one TextView. List view is populated from a string
I have a list view which is populated via records from the database. Now
I have a top list view in my current iPhone app, that's populated by
Hi I have an array adapter that is populated from an array like so:
I have AutoCompleteTextView attached to my view, and used ArrayAdapter to populate for list
I am working on an application in which I have a list populated in

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.