First of all, I put the code for the solution:
Package Com.park;
Import java.io.IOException;
Import Java.io.InputStream;
Import java.lang.reflect.InvocationTargetException;
Import Java.lang.reflect.Method;
Import java.util.Objects;
Import Java.util.Timer;
Import Java.util.TimerTask;
Import Java.util.UUID;
Import android.app.Activity;
Import Android.app.ProgressDialog;
Import android.content.Intent;
Import Android.os.AsyncTask;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import Android.os.ParcelUuid;
Import Android.text.format.Time;
Import Android.util.Log;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.Window;
Import Android.webkit.ConsoleMessage.MessageLevel;
Import Android.widget.ImageView;
Import Android.widget.TextView;
Import android.bluetooth.*;
Import Android.widget.Toast;
/**
* Created by Lenovo on 2015/5/25.
*/
public class Communityparking extends Activity implements View.onclicklistener {
Private ProgressDialog ProgressDialog, progressDialog2, ProgressDialog3;
private int parknum = 50;
Private ImageView back, around_parking, Zero, ten, Onehour, Threehour;
Private Intent Intent;
Private TextView num;
Private Handler Handler;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Setcontentview (r.layout.community_parking);
num = (TextView) Findviewbyid (r.id.num);
int a = 10;
back = (ImageView) Findviewbyid (r.id.back);
around_parking = (ImageView) Findviewbyid (r.id.around_parking);
Back.setonclicklistener (this);
Around_parking.setonclicklistener (this);
Timer timer = new timer ();
TimerTask timertask = new TimerTask () {
@Override
public void Run () {
TODO auto-generated Method Stub
Runonuithread (New Runnable () {
public void Run () {
parknum++;
Num.settext ("" + parknum);
Progressdialog.dismiss ();
}
});
}
};
ProgressDialog = Progressdialog.show (This, "", "Data loading, please later ...");
Timer.schedule (timertask, 4000, 4000);
Zero = (ImageView) Findviewbyid (R.id.zero);
Ten = (ImageView) Findviewbyid (R.id.ten);
Onehour = (ImageView) Findviewbyid (R.id.onehour);
Onehour.setonclicklistener (new test ());
Threehour = (ImageView) Findviewbyid (R.id.threehour);
Threehour.setonclicklistener (New Test2 ());
}
@Override
public void OnClick (View v) {
Switch (V.getid ()) {
Case R.id.back:
Intent = new Intent (this, mainactivity.class);
StartActivity (Intent);
Break
Case r.id.around_parking:
Intent = new Intent ();
Intent.setaction ("Android.intent.action.AROUPARK");
StartActivity (Intent);
Break
}
}
Class Test implements Onclicklistener {
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
PROGRESSDIALOG2 = Progressdialog.show (Communityparking.this, "",
"Parking estimate, please later ...");
Handler Handler = new Handler ();
Handler.postdelayed (New Runnable () {
public void Run () {
Progressdialog2.dismiss ();
Ten.setvisibility (view.visible);
}
}, 1000);
}
}
Class Test2 implements Onclicklistener {
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
ProgressDialog3 = Progressdialog.show (Communityparking.this, "",
"Parking estimate, please later ...");
Handler Handler = new Handler ();
Handler.postdelayed (New Runnable () {
public void Run () {
Progressdialog3.dismiss ();
Zero.setvisibility (view.visible);
}
}, 1000);
}
}
}
This is what I did in OnCreate (), Progressdialog.show (); The progress box can be displayed normally, but when I set a click event to an ImageView in an XML page, I call Progressdialgo.show ( ) cannot display the progress box. Because at first I defined the click Time, I let communityparking implements Onclicklistner, and then agreed to handle the click Monitoring event, but I found that this method could not display the wait dialog, and then I used pass new test (), Create a listener class for the Click event, and then you can display the Wait dialog box. It's not yet known why, but the problem has been solved.
One more thing, I started with the Thread.Sleep (). Let the thread pause for two seconds, but this is always wrong, and can not display the waiting prompt box, and then I searched the StackOverflow, said with handler to deal with the program to wait for the problem, and finally solve the problem. Specific people can refer to my code, what questions can leave a message.
Android Progressdialog.show (), unable to display the wait box