Android-Progress Processing dialog box (progressdialog)

Source: Internet
Author: User

Main.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " ><button    android:id= "@+id/btn"    android:layout_height= "wrap_content"    android:layout_width= " Wrap_content "    android:text=" Find network Connection "/>    </LinearLayout>


. Java code is as follows:

Package Org.lxh.demo;import Android.app.activity;import Android.app.alertdialog;import android.app.Dialog;import Android.app.progressdialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.adapterview.onitemselectedlistener;import Android.widget.button;import Android.widget.Spinner; Import Android.widget.textview;public class Hello extends Activity {private Button btn = null;private static final int MAX _progress=100; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);// Life cycle Method Super.setcontentview (R.layout.main); Set the layout manager to use THIS.BTN = (Button) Super.findviewbyid (R.ID.BTN); This.btn.setOnClickListener (New Onclicklistenerimpl ( ));} Private class Onclicklistenerimpl implements Onclicklistener {public void OnClick (View v) {final ProgressDialog prodialog=new ProgressDialog (hello.this);p rodialog.settitle ("Search Network");p rodialog.setmessage ("Please wait patiently ");p Rodialog.setprogressstyle (progressdialog.style_horizontal);p Rodialog.setmax (max_progress); Prodialog.setprogress (;p) Rodialog.setbutton ("Background processing", new Dialoginterface.onclicklistener () {public void OnClick ( Dialoginterface arg0, int arg1) {Prodialog.dismiss ();}}); Prodialog.onstart (); new Thread () {public void run () {for (int x=0;x<max_progress;x++) {try {thread.sleep;} catch (Interruptedexception e) {E.printstacktrace ();} Prodialog.incrementprogressby (1);} Prodialog.dismiss ();}}. Start ();p rodialog.show ();}}}


The effect runs as follows:



Android-Progress Processing dialog box (progressdialog)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.