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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:04:38+00:00 2026-06-09T17:04:38+00:00

Is there a method in the Android SDK that allows me to disable all

  • 0

Is there a method in the Android SDK that allows me to disable all UI-Elements such as Buttons and MenuItems while I perform a task in the background?

I currently do some work over the internet and display a ProgressBar informing the user about the current progress.

Should I just build a List<> of all my Buttons and MenuItems and update their state at the start and end of the background task via the setEnabled method?

  • 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-09T17:04:39+00:00Added an answer on June 9, 2026 at 5:04 pm

    Is there a method in the Android SDK that allows me to disable all
    UI-Elements such as Buttons and MenuItems while I perform a task in
    the background?

    I don’t recall of such a method being present in the SDK.

    Should I just build a List<> of all my Buttons and MenuItems and
    update their state at the start and end of the background task via the
    setEnabled method?

    My advice is to use a ProgressDialog instead of your current approach(the dialog will also prevent the users from interacting with the UI, you’ll just have to disable the menu). If you start the background worker and disable all the UI views the user will see that there is some work being done and also that he/she can’t use the app. For me this seems confusing and a Dialog seems a much better solution as it clearly indicates that the user must wait until the work is done. Another option is to place the ProgressBar in a overlay that will cover the activity so the user can still see the below UI if this is what you want.

    To disable all the views I would use a method like the one below:

    private void changeViewsState(ViewGroup parent, boolean state) {
        int count = parent.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = parent.getChildAt(i);
            if (child instanceof ViewGroup) {
                changeViewsState((ViewGroup) child, state);
            } else if (child instanceof View) {
                child.setEnabled(state);
            }
        }
    }
    

    passing the system’s content panel (changeViewsState((ViewGroup) findViewById(android.R.id.content), false);) or the root of your activity’s layout:

    ViewGroup root; // root is a reference of the root of your content view
    // in the onCreate method
    
    root = (ViewGroup) getLayoutInflater().inflate(R.layout.your_activity_layout_file, null);
    
    // later use it:
    changeViewsState(root, false);
    

    To disable the menu items have a boolean flag that is set when the background work is about to begin and use that flag to enable/disable menu items in the callback onPrepareOptionMenu. When the work finishes remember to revert the flag so the menu will be enabled.

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

Sidebar

Related Questions

When using the onPause method in the Android SDK, that code is run whenever
i'm new at Android world, and i have a doubt, is there any method
Starting with API level 9, there's android:filterTouchesWhenObscured attribute and corresponding setFilterTouchesWhenObscured method on ViewGroup
is there a method to link specific files so that I can reference them
Is there a method which allows to know parent item of leaf tapped item?
Is there builtin method that would do this or do I always have to
I currently have an app on the market that supports Android 1.5 (SDK level
The following code is from the Facebook Android SDK, and is used for all
Possible Duplicate: how to change position of Toast in android? Is there any method
Is there a way to implement interface which doesn't exist in Android SDK version

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.