Android dialog box (2) ProgressDialog
Main. xml
Custom_dialog.xml
Package com. example. progressdialog; import android. app. dialog; import android. content. context; import android. view. layoutInflater; import android. view. view; import android. widget. imageView; import android. widget. textView; public class CustomDialog {private Context context; Dialog dialog; public CustomDialog (Context context) {this. context = context; dialog = new Dialog (context);} public void show () {View = LayoutInflater. from (context ). inflate (R. layout. custom_dialog, null); // The second parameter of inflate is null, indicating that the layout of the current dialog box does not have a root layout dialog. setContentView (view);/** setContentView (R. layout. custom_dialog); * You can also load */dialog in this way. setTitle ("Custom dialog box"); ImageView imageView = (ImageView) view. findViewById (R. id. imageView1); imageView. setImageResource (R. drawable. ic_launcher); TextView textView = (TextView) view. findViewById (R. id. textView1); textView. setText ("this is a custom dialog box"); dialog. show ();}}
Package com. example. progressdialog; import android. app. activity; import android. app. progressDialog; import android. OS. bundle; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. view. onClickListener; import android. widget. button; public class MainActivity extends Activity {private Button button1; private Button button2; private Button button3; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); button1 = (Button) findViewById (R. id. button1); button2 = (Button) findViewById (R. id. button2); button3 = (Button) findViewById (R. id. button3); button1.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View arg0) {/** ProgressDialog. show (MainActivity. this, "prompt", "loading... please wait... "); * in this way, clicking the back button does not respond */ProgressDialog dialog = new ProgressDialog (MainActivity. this); dialog. setTitle ("prompt"); dialog. setMessage ("loading... please wait... "); dialog. show (); // display the progress bar. In this way, click the back button to exit the progress dialog box.}); button2.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View arg0) {/** first parameter: Context * second parameter: topic style int theme * First Writing Method * ProgressDialog dialog = new ProgressDialog (MainActivity. this, ProgressDialog. STYLE_HORIZONTAL); */ProgressDialog dialog = new ProgressDialog (MainActivity. this); dialog. setTitle ("Download prompt"); dialog. setProgressStyle (ProgressDialog. STYLE_HORIZONTAL); dialog. setProgress (50); // to display the progress, add the thread // dialog. setCancelable (false); dialog. show () ;}}); button3.setOnClickListener (new OnClickListener () {{@ Overridepublic void onClick (View arg0) {// TODO Auto-generated method stubCustomDialog dialog = new CustomDialog (MainActivity. this); dialog. show ();}});}}