是否可以更改 progressDialog 文本?
我的代码:
progressDialog = ProgressDialog.show(BackupActivity.this, "In progress", "test1");
new Thread() {
public void run() {
try{
sleep(10000);
} catch (Exception e) {
Log.e("tag", e.getMessage());
} progressDialog.dismiss();
}
}.start();
}
});
selectExportsDialog = builder.create();
}
selectExportsDialog.show();
break; }
我想在示例 10 秒后将 test1 更改为 test2。可能吗?
谢谢
最佳答案
你可以试试这个:
private class ProgressRunner extends AsyncTask<URL, Integer, Long>
{
protected void onPreExecute()
{
try
{
dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setTitle("TITLE");
dialog.setMessage("MY TEXT 1");
dialog.setCancelable(false);
dialog.setProgress(0);
dialog.setIndeterminate(false);
dialog.show();
}
catch (Exception e)
{
e.printStackTrace();
dialog.dismiss();
}
}
@Override
protected void onCancelled()
{
super.onCancelled();
dialog.dismiss();
}
@Override
protected Long doInBackground(URL... params)
{
// process the code here
dialog.setMessage("MY TEXT 2");
return null;
}
protected void onProgressUpdate(Integer... progress)
{
dialog.setProgress(progress[0]);
}
protected void onPostExecute(Long result)
{
try
{
dialog.dismiss();
}
catch (Exception e)
{
e.printStackTrace();
finish();
}
}
}
关于Android:更改进度对话框文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14727272/