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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:18:43+00:00 2026-05-19T03:18:43+00:00

I have 2 problems. The 1st problem. I have a CheckedTextView Select All item

  • 0

I have 2 problems.

The 1st problem.
I have a CheckedTextView “Select All” item and a list of array items set in a adapter of MutipleChoice. I am current trying to set the state of all the checkboxes of the array items to true/false by selecting the CheckedTextView. It works but there’s a bug. Such that when the last item of the array is true, the “SelectAll” to true will work, but if the last item of the array is false, it will uncheck all the items. What I want is even if any of the item’s state is false, it will be set to true when the checkedtextview is selected to true.

The 2nd problem.
I can’t seem to set the checkedtextview to true when all of the array item’s state is true.

Could it be that I’m doing it the wrong way? Help given would be appreciated..

This is my method for the CheckedTextView “Select All”

private void markAll (Boolean state) {

    for (int i = 0; i < lv.getCount(); i++) {
        lv.setItemChecked(i, state);
    }           
}

This is the coding for checking of the states of the array items

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    for(int i = 0; i < lv.getCount(); i++) {
        //if even 1 of the item is false, the checkedtextview will be set to false
        if(lv.isItemChecked(i) == false) {
            ctv.setChecked(false);
        }
        //if all of the item is true, the checkedtextview will be set to true as well
        //the coding should be done in the if-else below, if i'm not wrong
        if(...) {

        }
    }
}

EDIT
This is the new code for calling my method
ctv.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            ctv.setClickable(true);
            if(ctv.isPressed() && ctv.isChecked() == false) {
                ctv.setChecked(true);
                markAll(true);
            }
            else {
                ctv.setChecked(false);
                markAll(false);
            }
        }
    });

This is my xml code for the checkedtextview

    <CheckedTextView
        android:id="@+id/checkedtext"
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:text="Select all"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical"
        android:clickable="true"
        android:checkMark="?android:attr/listChoiceIndicatorMultiple"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"/>
  • 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-19T03:18:44+00:00Added an answer on May 19, 2026 at 3:18 am

    Try this reworked logic:

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    
        ctv.setChecked(true); // assume true at first
    
        // if even 1 of the item is false, the checkedtextview will be set to false
        for(int i = 0; i < lv.getCount(); i++) {
            if(lv.isItemChecked(i) == false) {
                ctv.setChecked(false);
                break; // exit loop if you have found one false
            }
        }
    }
    

    This will make your ctv have the checked state if all of the items in the list are checked, otherwise if any are false then ctv will have the unchecked state.

    To control what happens when you click ctv itself:

    ctv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(ctv.isChecked()) {
                    markAll(true); // ctv is checked, so make all others checked
            }
            else {
                  markAll(false); // ctv is unchecked, so make all others unchecked
            }
        }
    });
    

    You don’t need to check state of other items here – if it is just a ‘(de)select all’ button then it should just propagate its own state to the other items.

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

Sidebar

Related Questions

1st phase I have a problem shutting down my running JBoss instance under Eclipse
I have some problems on a site with the concurrent access to a list.
Currently I have this problem. Client downloads from server successfully only the 1st time.
I have problems with bringing a windows mobile 6 form to the front. I
I frequently have problems dealing with DataRows returned from SqlDataAdapters . When I try
I seem to always have problems with converting data to and from XML in
I've worked on several PHP projects and always I have problems with organizing my
I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I
Does anyone have any problems with VS2008 on Vista? For me every so often
I am very new to C and I have some problems learning about pointers.

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.