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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:17:32+00:00 2026-05-31T17:17:32+00:00

I added a button in a listview item, and after the button is clicked,

  • 0

I added a button in a listview item, and after the button is clicked, I want the button is disabled. I used the below setOnClickListener for my button in the custom adapter, but the problem is when i clicked on a button, the button of another list item will also be disabled. For example, when I clicked the button of item 1, the button of item 1 then is disabled, but the item 4’s button will also be disabled at the same time although i didn’t click on it.
And also, when I scroll up and down, all item’s button just enable and disable randomly.
Anyone know why is this happening?

   holder.viewBtn.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        holder.viewBtn.setEnabled(false);
                        showInfo();                 
                    }           });
  • 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-31T17:17:33+00:00Added an answer on May 31, 2026 at 5:17 pm

    I was so frustrated when I first faced this problem!

    The problem here is that the listview just doesn’t remember the state of the button. Dunno if it is a bug but anyways I needed a way out and this is what I did.

    I believe you are using a custom adapter with a viewholder. Means you are on the right path. You need to keep an array of booleans whose size is equal to the number of items in your list. in your btnClick() set the state of the item in the array.

    Now everytime you scroll, or do soemthing that makes the list redraw, getView() is called. Put a check in your getView() for the items state and enable/disable it. One more thing, Make sure you implement both if{} and else{} for the check.

    if(checked){
        holder.viewBtn.setEnabled(false);
    }else{
        holder.viewBtn.setEnabled(true);
    }
    

    if you don’t do this you’ll see weird behaviours. One more thing if you are using the

    if(convertview == null){
        //create the holder
    }else{
       convertview = getTag();
    }
    

    method, make sure you populate the state after the above step.

    I have not seen your implementation but I had to pop up a button in the item and then delete the item from the list using it. So I had to take extra care for maintaining the state.

    So be careful about the states once the underlying data has changed.

    Sorry about the long post but the problem is such 🙁

    I found a link that has the solution in a basic format

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

Sidebar

Related Questions

I want to show a button under a ListView . Problem is, if the
I created a button and added an action for it, but as soon as
I have a ListView, and I want to customize the layout of each item
I want to get some data to fill a listview control, but this data
I am trying to create a webform. I added a button control on the
I programatically create an NSToolbar in my application. I just added a new button
I added an image to button UIImage* deleteImage = [UIImage imageNamed:@Delete.png]; CGRect imageFrame=CGRectMake(-4,-4, 310,
I have added some dynamic textboxes upon a button click. I need the values
I've created a button (symbol), and added a OVER state, which covers a bigger
I have a page with some dynamically added buttons. If you click a button

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.