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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:32:51+00:00 2026-05-26T10:32:51+00:00

clipProgress resets a progress bar to zero: public class Whatever extends Activity implements ListenerA,

  • 0

clipProgress resets a progress bar to zero:

public class Whatever extends Activity implements ListenerA, ListenerB {
        private Handler mHandler = new Handler();

        ProgressBar myProgressBar;  
        int myProgress = 0;  

        public void clipProgress() {
            myProgressBar = (ProgressBar)findViewById(R.id.progressbar);  
            myProgressBar.setProgress(myProgress);  
        }

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

            clipProgress();

            public void onClick(View view) {
                Duration.duration = 0;
                startRecording();

                new Thread(new Runnable(){  
                    @Override  
                    public void run() {  
                        while(myProgress<100){  
                            try{  
                                myHandle.sendMessage(myHandle.obtainMessage());  
                                Thread.sleep(50);  
                            }catch(Throwable t){  
                            }  
                        }  
                    }  
                }).start();  
            }

        Handler myHandle = new Handler(){  
            @Override  
            public void handleMessage(Message msg) {  
                myProgress++;  
                myProgressBar.setProgress(myProgress);  
            }  
        };
    });
}

I have two different methods, below, where I suppose I could attempt to reset the progress bar to zero. But they both reside in a different class entirely:

@Override   protected void onPostExecute(Void result) {  
    Whatever.clipProgress();  //...which throws all kinds of red lines if I use this statement.
}

and

public void stopThis(){
    thing.stop();
    try {
        Whatever.clipProgress();  //...which throws all kinds of red lines if I use this statement.

        dos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Eclipse wants to apply “static” to various initializations in the Whatever class. But those fixes just leave findViewById(R.id.progressbar) redlined.

I just want to reset the progress bar (which was started from within class 1) from class 2. It’s too much to ask for.

UPDATE:
Whatever is the starting point, the Android Activity. Its handler, which I should have included in the above snip, right underneath onCreate is included in the snip below. So more completely, and invoked from a button, is thus:

        public void onClick(View view) {
            new Thread(new Runnable(){  
                @Override  
                public void run() {  
                    while(myProgress<100){  
                        try{  
                            myHandle.sendMessage(myHandle.obtainMessage());  
                            Thread.sleep(87);  
                        }catch(Throwable t){  
                        }  
                    }  
                }  
            }).start();  
        }

        Handler myHandle = new Handler(){  
            @Override  
            public void handleMessage(Message msg) {  
                myProgress++;  
                myProgressBar.setProgress(myProgress);  
            }  
        };

Once that button is pressed a listener is produced:

    myTask = new Task();
    myTask.addTaskListener(this);
    myTask.execute(this);

It is inside the Task class:

public class Task extends AsyncTask<Whatever, ArrayList<Float>, Void>{
...
    public void addTaskListener(TaskListener rl){
        this.rl = rl;
    }
...

that those two functions reside, one of which I’m hoping to use to stop the progress bar.

A task is designed elsewhere to shut down at exactly a constant number of seconds, and so I can hardcode 50 into that progress bar value on the sleep(). I just want to be able to shut the bar down back to zero earlier if I stop the task earlier.

  • 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-26T10:32:51+00:00Added an answer on May 26, 2026 at 10:32 am

    Eclipse warns you because you are accessing the clipProgress method in a static way (by calling Whatever.clipProgress()).

    Also, you should only assign your progress bar once, so move

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

    into your onCreate method.

    You should probably pass the ProgressBar into the other class that needs to update it, and then do something like

    myProgressBar.post(new Runnable() {
        public void run() {
            myProgressBar.setProgress(myProgress);
        }
    });
    

    this post method updates the ProgressBar on the UI thread, which is the only safe way to do it. Make sure you are only doing any of this if the activity with the ProgressBar is currently active.

    You should also question whether you need to update the progress bar in this other class at all. I only see you updating the myProgress variable inside your handler, where you set the progress on the bar immediately after. Could you explain a bit more about the relationship between this other class and the activity with your progress bar?

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

Sidebar

Related Questions

I have the following class. Which returns certain fields. I am interested in Reference.
I have a script which returns 5 columns from a php result. I am

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.