Android dialog box (2) ProgressDialog

Source: Internet
Author: User

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 ();}});}}

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.