Use of Dialogfragment

Source: Internet
Author: User

1  PackageCOM.WHJ.NTWB;2 3 ImportAndroid.annotation.SuppressLint;4 Importandroid.app.Activity;5 ImportAndroid.app.AlertDialog;6 ImportAndroid.app.Dialog;7 Importandroid.app.DialogFragment;8 ImportAndroid.content.DialogInterface;9 ImportAndroid.os.Bundle;Ten ImportAndroid.util.Log; One ImportAndroid.view.View; A ImportAndroid.view.View.OnClickListener; - ImportAndroid.widget.Button; - ImportAndroid.widget.TextView; the  -@SuppressLint ("Newapi") Public classMainactivityextendsactivity{ - @Override -     protected voidonCreate (Bundle savedinstancestate) { +         //TODO auto-generated Method Stub -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.layout_linearlayout); AView TV =Findviewbyid (r.id.text); at((TEXTVIEW) TV). SetText ("Example of displaying an alert dialog with a dialogfragment"); -  -             //Watch for button clicks. -Button Button =(Button) Findviewbyid (r.id.show); -Button.setonclicklistener (NewOnclicklistener () { -                  Public voidOnClick (View v) { in ShowDialog (); -                 } to             }); +     } -  the     voidShowDialog () { *Dialogfragment newfragment =Myalertdialogfragment.newinstance ( $ r.string.alert_dialog_two_buttons_title);Panax NotoginsengNewfragment.show (Getfragmentmanager (), "dialog"); -     } the  +      Public voidDopositiveclick () { A         //Do stuff here. theLOG.I ("Fragmentalertdialog", "Positive click!"); +     } -      $      Public voidDonegativeclick () { $         //Do stuff here. -LOG.I ("Fragmentalertdialog", "negative click!"); -     } the  -     Wuyi  the      Public Static classMyalertdialogfragmentextendsdialogfragment { -  Wu          Public StaticMyalertdialogfragment newinstance (inttitle) { -Myalertdialogfragment Frag =Newmyalertdialogfragment (); AboutBundle args =NewBundle (); $Args.putint ("title", title); - frag.setarguments (args); -             returnFrag; -         } A          + @Override the          PublicDialog Oncreatedialog (Bundle savedinstancestate) { -             inttitle = Getarguments (). GetInt ("title"); $              the             return NewAlertdialog.builder (getactivity ()) the . SetIcon (R.drawable.ic_launcher) the . Settitle (title) the. Setmessage ("ddddddddddd") - . Setpositivebutton (R.STRING.ALERT_DIALOG_OK, in                         NewDialoginterface.onclicklistener () { the                              Public voidOnClick (Dialoginterface Dialog,intWhichbutton) { the ( (mainactivity) getactivity ()). Dopositiveclick (); About                             } the                         } the                     ) the . Setnegativebutton (R.string.alert_dialog_cancel, +                         NewDialoginterface.onclicklistener () { -                              Public voidOnClick (Dialoginterface Dialog,intWhichbutton) { the ( (mainactivity) getactivity ()). Donegativeclick ();Bayi                             } the                         } the                     ) - . Create (); -         } the     } the}

Use of Dialogfragment

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.