抱歉,如果之前有人问过这个问题,但我找不到答案(我已经搜索过了!)
我试图按照 google/android 文档在我的应用程序执行冗长的任务时使不确定的进度条出现并旋转。
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());
}