One. Wait for the window to implement:
Note that sometimes when we download the data in order to improve the user experience, adding a waiting window is necessary, there are two waiting windows:
The first kind of rotating ProgressBar:
Main interface:
public class Mainactivity extends Activity {private Button button1;private TextView textview1;public alertdialog selfdial Og;private mainactivity Main; Public Handler Mhandler = new Handler () {public void Handlemessage (Message msg) {switch (msg.what) {//display textviewcase 1:toa St.maketext (Main, "success", Toast.length_short). Show (); textview1.setvisibility (view.visible); break;} Super.handlemessage (msg);}}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); main = This;button1 = (Button) Findviewbyid (r.id.button1); textview1 = (TextView) Findviewbyid ( R.ID.TEXTVIEW1); Button1.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View arg0) { Showdialogloading ();}});} Wait dialogprivate void showdialogloading () {Layoutinflater inflater = (layoutinflater) This.getsystemservice (this. Layout_inflater_service);//viewview view = Inflater.inflate (R.layout.footer, NULL); Alertdialog.builder ad = new AlerTdialog.builder (this); Selfdialog = Ad.create (); Selfdialog.setview (view);//Mask off click Selfdialog.setcancelable (FALSE); Selfdialog.show (); new Thread () {@Overridepublic void run () {try {thread.sleep ()} catch (Interruptedexception e) { E.printstacktrace ();} Message message = new Message (); message.what = 1;main.mhandler.sendmessage (message);//close Dialogselfdialog.dismiss ();}}. Start ();}}
Activity_main.xml:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" wrap_content " android:o rientation= "vertical" android:gravity= "center" > <button android:id= "@+id/button1 " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "click Me" /> <textview android:id= "@+id/textview1" android:layout_width= "Wrap_content" android: layout_height= "Wrap_content" android:text= "Show me after loading complete" android:visibility= "Gone" /></ Linearlayout>
Footer.xml:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" wrap_content " android:o rientation= "vertical" android:gravity= "center" > <button android:id= "@+id/button1 " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "click Me" /> <textview android:id= "@+id/textview1" android:layout_width= "Wrap_content" android: layout_height= "Wrap_content" android:text= "Show me after loading complete" android:visibility= "Gone" /></ Linearlayout>
So the first kind of waiting window is realized.
The second type of waiting window for progress bars:
Main interface:
public class Mainactivity extends Activity {private Button button1;private TextView textview1;private TextView textview2; Public Alertdialog selfdialog;private mainactivity main; Public Handler Mhandler = new Handler () {public void Handlemessage (Message msg) {switch (msg.what) {//display textviewcase 1:tex Tview2.settext ("Downloading (" +msg.obj.tostring () + "/10)"); Super.handlemessage (msg);}}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); main = This;button1 = (Button) Findviewbyid (r.id.button1); textview1 = (TextView) Findviewbyid ( R.ID.TEXTVIEW1); Button1.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View arg0) { Showdialogloading ();}});} Wait dialogprivate void showdialogloading () {Layoutinflater inflater = (layoutinflater) This.getsystemservice (this. Layout_inflater_service);//viewview view = Inflater.inflate (R.layout.footer, NULL); final ProgressBar progressbar1 = ( ProgressBar) View.findviewbyid (r.id.progressbar1); textview2 = (TextView) View.findviewbyid (R.ID.TEXTVIEW2); Alertdialog.builder ad = new Alertdialog.builder (this); Selfdialog = Ad.create (); Selfdialog.setview (view);// Mask off Click Selfdialog.setcancelable (False); Selfdialog.show (); new Thread () {@Overridepublic void run () {//getprogress () Gets the current progress value//incrementprogressby () each increment of the amount//getmax () gets the upper bound of the range of this progress bar int max = Progressbar1.getmax (); int i = 0;while (true) {if (i > Max) {break;} try {thread.sleep ();p Rogressbar1.incrementprogressby (1); Message message = new Message (); message.what = 1;message.obj = Progressbar1.getprogress (); Main.mhandler.sendMessage ( message); i++;} catch (Interruptedexception e) {e.printstacktrace ();}} Close Dialogselfdialog.dismiss ();}}. Start ();}}
Footer.xml:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" wrap_content " android:o rientation= "vertical" android:gravity= "center" > <progressbar android:id= "@+id/progressbar1" style= "? android:attr/progressbarstylehorizontal" android:layout_width= "200dip" android:layout_ height= "Wrap_content" android:max= "ten" /> <textview android:id= "@+id/textview2" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Downloading (0/10)" android:textcolor= "@android: Color/black" android:textsize= "9SP"/></linearlayout>
The Activity_main is the same as the previous example layout.
Android (5) Wait window