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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:17:03+00:00 2026-06-02T23:17:03+00:00

What my application first does is it loads ListView whose items have invisible CheckBoxes

  • 0

What my application first does is it loads ListView whose items have invisible CheckBoxes by setting its visibility View.Gone. When the user tabs a menu button then it will turn on and off the CheckBox visibility and some other layouts. Below is the code, I removed some unnecessary parts:

private void editmodeSwitch(boolean flag){
    // get topbar, bottombar, and bottombar2
    LinearLayout topbar = (LinearLayout) findViewById(R.id.task_topbar_linearLayout);
    LinearLayout bottombar = (LinearLayout) findViewById(R.id.task_bottombar1_linearlayout);
    LinearLayout bottombar2 = (LinearLayout) findViewById(R.id.task_bottombar2_linearlayout);

    if(flag){
        isEditmodeOn = true;            

        // make topbar and bottombar2 visilble, but bottombar gone
        topbar.setVisibility(View.VISIBLE);
        bottombar.setVisibility(View.GONE);
        bottombar2.setVisibility(View.VISIBLE);

        // make checkboxes visible in listview visible as well
        for(int i=0; i<listView.getChildCount(); i++){
            LinearLayout ll = (LinearLayout) listView.getChildAt(i);
            CheckBox cb = (CheckBox) ll.findViewById(R.id.task_row_checkBox1);
            cb.setVisibility(View.VISIBLE);
        }
    }
    else{
        isEditmodeOn = false;

        topbar.setVisibility(View.GONE);
        bottombar.setVisibility(View.VISIBLE);
        bottombar2.setVisibility(View.GONE);

        // set each checkbox false and its visibility gone
        for(int i=0; i<listView.getChildCount(); i++){
            LinearLayout ll = (LinearLayout) listView.getChildAt(i);
            CheckBox cb = (CheckBox) ll.findViewById(R.id.task_row_checkBox1);
            cb.setVisibility(View.GONE);
            cb.setChecked(false);
        }
    }
}

It works fine but the problem is the application doesn’t work when the screen rotates(changes the screen orientation). Everything worked fine as it displayed some layouts but only CheckBoxes in list items. Below is the code inonCreate()`:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.task_layout);

    initialize();
    loadDB();
    updateListAdapter(list_title, list_date);

    // in case of screen rotation
    if(savedInstanceState != null){
        isEditmodeOn = savedInstanceState.getBoolean(EDITMODE_CHECK);
        isItemChecked = savedInstanceState.getBoolean(ITEM_CHECK);

        if(isEditmodeOn){
            if(!isItemChecked){
                Log.i(tag, "item NOT checked");
                editmodeSwitch(true);
            } else{
                //this is something different so please don't mind
                deditmodeSwitch(savedInstanceState.getBooleanArray(LIST_CB_CHECK));
            }
        }
    }
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // save values for rotation
    outState.putBoolean(EDITMODE_CHECK, isEditmodeOn);
    outState.putBoolean(ITEM_CHECK, isItemChecked);
    outState.putBooleanArray(LIST_CB_CHECK, list_cb_check);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    Log.i(tag, "you're in onRestoreInstanceState()");

    // in case of screen rotation
    if(savedInstanceState != null){
        isEditmodeOn = savedInstanceState.getBoolean(EDITMODE_CHECK);
        isItemChecked = savedInstanceState.getBoolean(ITEM_CHECK);

        if(isEditmodeOn){
            if(!isItemChecked){
                Log.i(tag, "item NOT checked");
                editmodeSwitch(true);
            } else{
                // this is for something else so please ignore this part
                editmodeSwitch(savedInstanceState.getBooleanArray(LIST_CB_CHECK));
            }
        }
    }

What I guessed is the ListView is being loaded at the end. Therefore, even if the code in onCreate() makes CheckBoxes visible, the CheckBoxes will become invisible again as its initialization in xml will do so. However, I’m stuck here and need your advice to solve this problem. Can anyone help me?

Just in case, below is the checkbox code of layout xml file for getview.

<CheckBox android:id="@+id/task_row_checkBox1" android:gravity="right" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:visibility="gone"
    />
  • 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-02T23:17:04+00:00Added an answer on June 2, 2026 at 11:17 pm

    Based on my experience, getview seems to be triggered at the end and it was why ‘onRestoreInstanceState()’ and ‘onConfigurationChanged()’ could not make it as getview will reset my checkboxes invisible as initialization in the layout xml file.

    Therefore, the only solution I could find out was I must control them in getview for the answer.

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

Sidebar

Related Questions

I have been writing a small java application (my first!), that does only a
I am attempting to build my first Google TV application and the documentation does
in my application the first view is an UIView with a couple of uilabel
I'm creating my first application and I have a window consisting of multiple subclasses
I have build my very first application to Android and I want now to
I have an application that uses the DevExpress XtraScheduler technology, that onLoad does a
What the application does is very simple. It loads two RSS feeds and on
I have an iPhone application that loads succesive views in a framework based on
When my application first runs I'm using some simple code to read in some
In my application I first display to the user a disclaimer page as the

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.