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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:50:41+00:00 2026-05-22T01:50:41+00:00

I have an example like this: package android.uiexample; import android.app.Activity; import android.os.Bundle; import android.os.Handler;

  • 0

I have an example like this:

package android.uiexample;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class BasicViewsExampleActivity  extends Activity 
{

private static int progress = 0;
private ProgressBar progressBar;
private int progressStatus = 0;
private Handler handler = new Handler();

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basic_views);

    progressBar = (ProgressBar) findViewById(R.id.progressbar);

    //---do some work in background thread---
    new Thread(new Runnable() 
    {
        public void run() 
        {
            //---do some work here---
            while (progressStatus < 10) 
            {
                progressStatus = doSomeWork();
            }



            //---hides the progress bar---
            handler.post(new Runnable() 
            {
                public void run() 
                {
                    progressBar.setVisibility(View.GONE);
                }
            });

        }    

        //---do some long lasting work here---
        private int doSomeWork() 
        {
            try {
                //---simulate doing some work---
                Thread.sleep(500);
            } catch (InterruptedException e) 
            {
                e.printStackTrace();
            }
            return ++progress;
        }

    }).start();
}

}

In this example, it use Handler to post a Runable to exc progressBar.setVisibility(View.GONE);. I don’t know why i can’t call progressBar.setVisibility(View.GONE); directly:

            //---do some work here---
            while (progressStatus < 10) 
            {
                progressStatus = doSomeWork();
            }



            //---hides the progress bar---
            progressBar.setVisibility(View.GONE);

Anybody can tell me why i can’t?

  • 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-22T01:50:42+00:00Added an answer on May 22, 2026 at 1:50 am

    The android UI framework (like pretty much every UI framework before it) only allows you to update the UI state from the main thread. You may want to look at AsyncTask which include the plumbing needed to route progress updates onto the main thread.

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

Sidebar

Related Questions

I have a base class like this: package MyClass; use vars qw/$ME list of
Let's Say I Have This Class: package{ import flash.display.Sprite; public class Main extends Sprite{
For example I have a simple class like public class Person{ public int Age
I have a Struts + Velocity structure like for example, a Person class, whose
I have a custom c# type like (just an example): public class MyVector {
I have a SQL table like so: Update: I'm changing the example table as
Say I have a site on http://example.com . I would really like allowing bots
How do I create subdomain like http://user.mywebsite.example ? Do I have to access .htaccess
I have modified the guestbook example shipped with google app engine (java) to include
is it possible to do something like this: Let's say I have a lot

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.