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<=ma
xprogress) {mprogressdialog.setprogress (currentprogress++);
Thread.Sleep (500);
} mprogressdialog.cancel ();
catch (Exception e) {mprogressdialog.cancel ();
}
};
}.start ();
Break
Default:break; }
}
}
}