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

  • Home
  • SEARCH
  • 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 7810431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:46:47+00:00 2026-06-02T03:46:47+00:00

I’ve searched around for a solution to my problem but couldn’t find one so

  • 0

I’ve searched around for a solution to my problem but couldn’t find one so here it is.

I have a arraylist of data that i display using a combination of textview and checkbox. This is done using custom adapter which basically inflates it row by row. Everything up to this point is fine until i want to retrieve the checked data.

What i read from other people is that their checked boxes becomes unchecked when scrolled due to the recycling of the view. For me the state of the checkboxes remain but i don’t know how to retireve them without scrolling it. When i check a box it is “check” on the UI but actaully it is not recognized until i scroll the checked item out of view and back in again.

Currently i use a global arraylist to populate with list.get(position).getName() if the list.get(position).isSelected() == true. But you see this arraylist remains empty unless i scroll the item out of view and back again. the same applies when the boxes are unchecked, they remain in the arraylist until i scroll. What i have in mind is a submit button that takes all the checkbox’s current state when it is clicked then construct the arraylist.

any idea how to create such thing?

public View getView(int position, View convertView, ViewGroup parent) {
    View view = null;
    if (convertView == null) {
        LayoutInflater inflator = context.getLayoutInflater();
        view = inflator.inflate(R.layout.qlist, null);

        final ViewHolder viewHolder = new ViewHolder();
        viewHolder.text = (TextView) view.findViewById(R.id.label);
        viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
        viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {


            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Model element = (Model) viewHolder.checkbox.getTag();
                //
                if(isChecked){
                    selctionCount++;
                }
                else if (!isChecked){
                    selctionCount--;
                }
                if(selctionCount > 2)
                {
                     Toast.makeText(context, "error, you checked more than 2!", Toast.LENGTH_LONG).show();
                     element.setSelected(false);
                }
                else
                {
                    element.setSelected(buttonView.isChecked());
                }
                System.out.println(selctionCount);
            }
        });
        view.setTag(viewHolder);
        viewHolder.checkbox.setTag(list.get(position));

    } 
    else {
        view = convertView;
        ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
    }
    ViewHolder holder = (ViewHolder) view.getTag();
    holder.text.setText(list.get(position).getName());

    //This is the problem here! the selected arraylist (global) is empty even when i check the boxes, 
    //it only populates when i scroll the checked boxes out of view and back in! helphelp!
    holder.checkbox.setChecked(list.get(position).isSelected());
    if (list.get(position).isSelected() == true){
        selected.add(list.get(position).getName());
    }
    else if (list.get(position).isSelected() == false){
        selected.remove(list.get(position).getName());
    }
    return view;
}

}

  • 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-02T03:46:49+00:00Added an answer on June 2, 2026 at 3:46 am

    I have already messed up with the similar problem. You can initially call a function in your constructor which initialize the states of your checkboxes as false and save all states in your arraylist. Whenever checkbox will be clicked just check the box and save its state in boolean arraylist.
    Later you can retrieve your states from arraylist.
    If you havn’t understand then let me know I will try to send some lines of code to help you…

    Here is a little code for your help:
    I will create a boolean arraylist.

    private ArrayList<Boolean> itemChecked      = null;
    

    Then I will set states of all checkboxes as false in my constructor:

        for (int i=0; i < no_of_elements.size(); i++) {
            itemChecked.add(i, false);
        }
    

    Set the actual checked state when checkbox clicked:

            holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                                             boolean isChecked) {
                    itemChecked.set(position, isChecked);
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.