In an Android app, I am trying to make a ProgressBar visible when a button is clicked, conduct some processes, and then make the bar invisible again. A general overview of my button's onClick method is shown below:
ProgressBar bar = (ProgressBar)findViewById(R.id.prog_bar);
bar.setVisibility(View.VISIBLE);
...do some stuff...
bar.setVisibility(View.INVISIBLE);
However, when I run the code, while the process in the middle is completed, the ProgressBar never shows up. Any ideas?
OnClick is called on the main thread. Your changes to the ProgressBar will not have any visible effect until your OnClick method returns. By that time, you've already finished all your work and hidden it again.
Move your work to a background thread. Not only will this make your app more responsive, it will allow the prograss bar to appear. (Note that, when your work is finished, you'll have to hide the progress bar from the main thread, not the worker thread. Typically you post a Message to a Handler to achieve this.)