我正在为包含进度条和文本视图的对话框使用自定义布局。如果对话框中的文本已经在运行,我想更改它。这是我执行此操作的代码。
private static Dialog progressDialog = null;
public static void showLoadingProgress(String msg){
Log.d("Util", "show loading progress"+progressDialog);//No i18n
if(progressDialog!=null && progressDialog.isShowing()){
TextView message = (TextView)progressDialog.findViewById(R.id.progressmsg);
message.setText(msg);
}else{
progressDialog = new Dialog(MainActivity.getActivity().getApplicationContext());
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setCancelable(false);
progressDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
progressDialog.setContentView(R.layout.customprogress);
TextView message = (TextView)progressDialog.findViewById(R.id.progressmsg);
message.setText(msg);
progressDialog.show();
Log.d("",progressDialog.isShowing()+""); //No i18n
}
}
public static void hideLoadingProgress(){
Log.d("Util", "close loading progress"+progressDialog);//No i18n
if(progressDialog!=null){
Log.d("ProgressDialog is not null, so making it null",""); //No i18n
progressDialog.dismiss();
progressDialog = null;
}
}
我正在从 try 块和从 asyncTask doInBackground() 的 catch 块中调用此方法。第一次从 try 块调用显示对话框,但如果发生任何错误,再次从 catch 块调用发生并抛出此异常
03-26 13:42:53.002: E/AndroidRuntime(16151): java.lang.RuntimeException: An error occured while executing doInBackground()
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.os.AsyncTask$3.done(AsyncTask.java:299)
03-26 13:42:53.002: E/AndroidRuntime(16151): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
03-26 13:42:53.002: E/AndroidRuntime(16151): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
03-26 13:42:53.002: E/AndroidRuntime(16151): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-26 13:42:53.002: E/AndroidRuntime(16151): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-26 13:42:53.002: E/AndroidRuntime(16151): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-26 13:42:53.002: E/AndroidRuntime(16151): at java.lang.Thread.run(Thread.java:856)
03-26 13:42:53.002: E/AndroidRuntime(16151): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4746)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:823)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.View.requestLayout(View.java:15468)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.View.requestLayout(View.java:15468)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.View.requestLayout(View.java:15468)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.View.requestLayout(View.java:15468)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:318)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.View.requestLayout(View.java:15468)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.view.View.requestLayout(View.java:15468)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.widget.TextView.checkForRelayout(TextView.java:6313)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.widget.TextView.setText(TextView.java:3567)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.widget.TextView.setText(TextView.java:3425)
03-26 13:42:53.002: E/AndroidRuntime(16151): at android.widget.TextView.setText(TextView.java:3400
请帮我解决这个问题。