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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:53:10+00:00 2026-05-29T23:53:10+00:00

I know that this question has been asked over and over again but still

  • 0

I know that this question has been asked over and over again but still I’ve not been a able to find a suggestion that really helps me. The checkbox is unchecked whenever the list is scrolled down. Yes I’m using a boolean array to store the values but this still doesn’t fix the problem. Here is my code. Please suggest a solution for this. Thank you.

 public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
        final ViewHolder holder;
final boolean[] itemChecked=new boolean[30];

    LayoutInflater inflater =  context.getLayoutInflater();  
    if(convertView==null)  
    {  
        convertView = inflater.inflate(R.layout.custom_list, null);
        holder = new ViewHolder();  
        holder.txtViewTitle = (TextView) convertView.findViewById(R.id.title_text);  
        holder.txtViewDescription = (TextView) convertView.findViewById(R.id.description_text);  
        holder.cb=(CheckBox) convertView.findViewById(R.id.cb);
        convertView.setTag(holder);  

    }  

    else  
    {
        holder=(ViewHolder)convertView.getTag();  

     }  

    holder.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                 itemChecked[position] = isChecked;
                 if(itemChecked[position])
                 {
                     holder.cb.setChecked(true);
                 }
                 else
                 {
                     holder.cb.setChecked(false);
                 }
      holder.txtViewTitle.setText(title[position]);  
    holder.txtViewDescription.setText(description[position]);  
    holder.cb.setChecked(itemChecked[position]);
  holder.txtViewDescription.setFocusable(false);
  holder.txtViewTitle.setFocusable(false);

return convertView;  

}  

}
  • 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-29T23:53:11+00:00Added an answer on May 29, 2026 at 11:53 pm

    getView() is called whenever a previously invisible list item needs to be drawn. Since you recreate itemChecked[] each time this method is called you will have the new checkbox unchecked and a different Array for each resulting View. (final in Java does not make that field unique like in C)
    Simplest way to solve that is to make itemChecked a classmember and set / restore checkbox state based on that one.

    public class MyListAdapter extends ArrayAdapter<Object> {
        private final boolean[] mCheckedState;
        private final Context mContext;
    
        public MyListAdapter(Context context, int resource, int textViewResourceId, List<Object> objects) {
            super(context, resource, textViewResourceId, objects);
            mCheckedState = new boolean[objects.size()];
            mContext = context;
        }
    
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // simplified to just a Checkbox
            // ViewHolder and OnCheckedChangeListener stuff left out 
            CheckBox result = (CheckBox)convertView;
            if (result == null) {
                result = new CheckBox(mContext);
            }
            result.setChecked(mCheckedState[position]);
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question has been asked over and over again, but nothing
I know that this type of question has been asked over and over again,
I know that this question has a been asked many times, but I still
I know this is a question that has been discussed over and over, but
I know this question has been asked before but I really couldn't find anything
I know that this question has been asked loads of times, but I have
I know this question has been asked/answered but I can't find it for the
I hope this question has not been asked yet, but I want to know
I know this question has been asked many times over, but I am currently
I know this question has been asked before but I still haven't seen a

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.