Sorry if this has been asked before but I cannot find the answer for this (I have searched!)
I have tried to follow the google/android documentation to make an indeterminate progressbar appear and spin while my app does a lengthy task.
protected void readData(final String whatToFind)
{
try
{
if (whatToFind.length() == 0)
{
adapter.notifyDataSetChanged();
return;
}
mProgress.setVisibility(View.VISIBLE);
mProgressText.setVisibility(View.VISIBLE);
m_dialog = new ProgressDialog(this);
m_dialog.setTitle("Searching...");
m_dialog.setMessage("Please wait while searching...");
m_dialog.setIndeterminate(true);
m_dialog.setCancelable(true);
m_dialog.show();
new Thread(new Runnable()
{
public void run()
{
mHandler.post(new Runnable()
{
public void run()
{
while (LotsOfWorkGoingOn)
{
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(m_i); /// vain attempt to make the progressbar spin
}
});
mProgress.setVisibility(View.GONE);
mProgressText.setVisibility(View.GONE);
m_dialog.hide();
}
});
}
}).start();
}
catch (Exception ex)
{
Log.e(LOGid, "Error listing items:" + ex.getStackTrace());
}
setProgress
only have effect when the progressbar is not Indeterminate.
Indeterminate means that, it has no progress amount, and it's used when you don't know the amount of progress done/remaining to end the task.
As stated in the documentation:
A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation without an indication of progress. This mode is used by applications when the length of the task is unknown. The indeterminate progress bar can be either a spinning wheel or a horizontal bar.
On the other hand, if you don't even see the progress bar, maybe you have a light background?
Try to set the style attribute to:
style="@android:style/Widget.ProgressBar.Inverse"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With