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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:47:27+00:00 2026-05-27T03:47:27+00:00

I have the following issue. I have a ListView and I am using a

  • 0

I have the following issue. I have a ListViewand I am using a custom adapter extending the ArrayAdapterclass. In each row there is a follow Button, when I click on it I need to change its style.

So far I have:

public View getView(final int position, View convertView, ViewGroup parent) {
        View vi = convertView;

        if (convertView == null) {  
            vi = inflater.inflate(R.layout.people_item, null);

            mViewHolder = new ViewHolder();              
            mViewHolder.follow = (Button) vi.findViewById(R.id.people_item_btn_follow);
            mViewHolder.name = (TextView)....
            vi.setTag(mViewHolder);         
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }

        mViewHolder.follow.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Changing the style of the button
                if(mData[position].getFollow().equals("0")) {
                    mViewHolder.follow.setBackgroundDrawable(mCtx.getResources().getDrawable(R.drawable.unfollow_button_border));
                    mViewHolder.follow.setText(mCtx.getString(R.string.unfollow));
                } else {
                    mViewHolder.follow.setBackgroundDrawable(mCtx.getResources().getDrawable(R.drawable.follow_button_border));
                    mViewHolder.follow.setText(mCtx.getString(R.string.follow));
                }

                mSharedAsyncTasks.getFollowerTask().execute(mData[position].getId());
            }
        });

        if(mData[position] != null) {
            // Setting data
        }

        return vi;
    }

private static class ViewHolder {
    TextView fullName;
    Button follow;
}

The problem is that when clicking on a button of any row, the new style is applied on the button of another row (although the effect of the following is being applied to the right row).

I know it has to do with the fact that the row are getting recycled/reused.

But how to actually solve this?

Thanks!

  • 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-05-27T03:47:28+00:00Added an answer on May 27, 2026 at 3:47 am

    Not sure you want to do the following.

     public void onClick(View v) {
          mViewHolder.follow.setBackgroundDrawable(mCtx.getResources().getDrawable(R.drawable.unfollow_button_border));
          ...
     }
    

    Specifically, the issue i think is your referencing mViewHolder which looks like its hanging around and could point to any button as you scroll. Its a scoping issue that you should be able to resolve with the following. in the onClick(View v) v i believe is the button you’ve clicked.

    Instead you should be able to do the following

     public void onClick(View v) {
          ((Button)v).setBackgroundDrawable(mCtx.getResources().getDrawable(R.drawable.unfollow_button_border));
          ...
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following issue using java 1.4 I try to display a very
I am using Django 1.3 and have the following issue: In the Admin list
I have a ListView with custom adapter which is populated from local sqlite database.
I have the following issue. I'm using devise as an authentication module for my
I have the following issue with XSL namespaces. I produce a PDF using FOP
Currently I face the following issue - I create a custom ListView ( 1
I have the following issue. On load I want to use each to go
I have a following issue - I'm using jQuery to add additional input forms
I have the following issue related to iterating over an associative array of strings
I have the following issue and I would like to know what exactly happens.

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.