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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:44:01+00:00 2026-05-19T17:44:01+00:00

I have a button that onclick reads and shows to the user a list

  • 0

I have a button that onclick reads and shows to the user a list with rss news. I would like to add a progress bar until finish loading. My problem is that, if I add a bar, it works properly at first but if I press the back button, the bar starts again and it can’t stop. Any help or a tutorial that demonstrates a progressbar would be appreciated. Thanks!

ProgressBar myProgressBar;
  int myProgress = 0;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main1);

  Button nea = (Button) findViewById(R.id.nea);
   nea.setOnClickListener(new View.OnClickListener() {
   public void onClick (View view) {
    setContentView(R.layout.bar);

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

           new Thread(myThread).start();

    Intent myIntent = new Intent(view.getContext(), nea.class);
    startActivityForResult(myIntent, 0);
    }  
  });
}

private Runnable myThread = new Runnable(){    
    @Override
    public void run() {
     // TODO Auto-generated method stub
     while (myProgress<100){
      try{
       myHandle.sendMessage(myHandle.obtainMessage());
       Thread.sleep(1000);
      }
      catch(Throwable t){
      }
     }
    }

    Handler myHandle = new Handler(){

     public void handleMessage(Message msg) {
      // TODO Auto-generated method stub
      myProgress++;
      myProgressBar.setProgress(myProgress);
     }
    };
      };
  • 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-19T17:44:01+00:00Added an answer on May 19, 2026 at 5:44 pm

    Actually I’d implement this with an AsyncTask, where you start the progress bar in onPreExecute(), cancel it in onPostExecute() and do the downloading in doInBackground(). If you want to update the progress value, you can publishProgress() from doInBackground() which can then be updated on the ProgressBar in onProgressUpdate()

    https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/TweetListActivity.java#L328
    shows how an example of an AsyncTask that uses those methods and which shows / hides a progress bar ( pg variable )

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

Sidebar

Related Questions

I have a webpage that shows some news, and a button that when is
I have a button that I'm creating in a UIViewController like so: TOLoginButton* button
I have a button that, when pressed, will add a new HTML row. Within
I have a line of code that reads as follows :- <input type='button' name='p_send'
I have a button that when clicked will run a stored procedure on a
I have a button that opens a dialog when clicked. The dialog displays a
I have a button that is programatically created, it's content is a stack panel
I have a button that plays an audio file on its click listener. If
I have a button that launches the google maps app on my device via
I have a button that opens a panel in a popup window and then

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.