Android List dialog box and progress Dialog

Source: Internet
Author: User
Tags xmlns

Main.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"
    xmlns:tools= "http:// Schemas.android.com/tools "
    android:layout_width=" fill_parent "
    android:layout_height=" Fill_parent
    " Android:gravity= "Center_horizontal"
    android:orientation= "vertical"
    >

    <button
        android:id= "@+id/listdialogbutton"
        android:layout_width= "wrap_content"
        android:layout_height= "Wrap_content"
        android:text= "@string/listdialog_button" 
        android:layout_margintop= "100dip"
        android:textsize= " 20sp "
     />
    
    <button
        android:id=" @+id/progressdialogbutton "
        android:layout_width=" Wrap_ Content "
        android:layout_height=" wrap_content "
        android:text=" "@string/progressdialog_button 
        " android:layout_margintop= "100dip"
        android:textsize= "20sp"
     />

</LinearLayout>


Mainactivity

Import android.app.Activity;
Import Android.app.AlertDialog.Builder;
Import Android.app.Dialog;
Import Android.app.ProgressDialog;
Import Android.content.DialogInterface;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.Toast;
    public class Mainactivity extends activity {private Button Mlistbutton;
    Private Button Mprogressbutton;
    Private Dialog Mlistdialog;
    Private ProgressDialog Mprogressdialog;
    private int currentprogress=0;
	private int maxprogress=100;
		@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
		Setcontentview (R.layout.main);
	Init ();
    	private void Init () {mlistbutton= (Button) Findviewbyid (R.id.listdialogbutton);
    	Mlistbutton.setonclicklistener (New Buttononclicklistenerimpl ());
    	mprogressbutton= (Button) Findviewbyid (R.id.progressdialogbutton); Mprogressbutton.setonclicklistener(New Buttononclicklistenerimpl ());
			Private class Buttononclicklistenerimpl implements Onclicklistener {@Override public void OnClick (view view) { Switch (View.getid ()) {case R.id.listdialogbutton:builder listbuilder=new Builder (mainactivity.this)
                ;
                Listbuilder.seticon (R.drawable.ic_launcher);
                Listbuilder.settitle (Getresources (). getString (R.string.list_dialog_title)); Listbuilder.setitems (Getresources (). Getstringarray (R.array.listdialogarray), new Dialoginterface.onclicklistener () {@Override public void OnClick (Dialoginterface dialog, int which) {String selected=getresources (). Get
						Stringarray (R.array.listdialogarray) [which];
					Toast.maketext (mainactivity.this,selected, Toast.length_short). Show ();
                }
				});
                Mlistdialog=listbuilder.create ();
                Mlistdialog.show ();
			Break Case R.id.progressdialogbutton:mprogressdialog=new ProgresSdialog (Mainactivity.this);
				Mprogressdialog.setmax (maxprogress);  
				Mprogressdialog.setprogressstyle (progressdialog.style_horizontal);
				Mprogressdialog.settitle (R.string.progress_dialog_title);
				Mprogressdialog.seticon (R.drawable.ic_launcher);
				Mprogressdialog.setmessage (Getresources (). getString (R.string.progress_dialog_message));
                Mprogressdialog.setcancelable (FALSE);
                Mprogressdialog.show (); New Thread () {public void run () {try {Currentprogress&lt;=ma
                    			xprogress) {mprogressdialog.setprogress (currentprogress++);
                    		Thread.Sleep (500);
						} mprogressdialog.cancel ();
						catch (Exception e) {mprogressdialog.cancel ();
                }
                		
                	};
               
				}.start ();
			Break
			Default:break; }
		}

	}
	
}
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.