dialog data transfer to activity

Source: Internet
Author: User

Popupdialog declares an internal interface Prioritylistener, which declares a callback function Refreshpriorityui, which refreshes the UI display of the activity after a dialog listener event is triggered. This interface is then implemented in the button click event in Mainactivity and passed as a parameter to the Popupdialog constructor, and implements the Refreshpriorityui () method. Not much to say, directly on the code--
Popupdialog Code:

 Public classPopupdialog extends Dialog {/** * Custom Dialog Listener*/     Public InterfacePrioritylistener {/** * Callback function to refresh activity's UI display after the dialog listener event is triggered*/         Public voidRefreshpriorityui (Stringstring); }        PrivatePrioritylistener Listener; /** * constructor with listener parameters*/     PublicPopupdialog (Context context,inttheme, Prioritylistener Listener)        {Super (context, theme);  This. Listener =Listener; }    protected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);         Setcontentview (R.layout.popup_dialog); Button buttonUp=(Button) Findviewbyid (R.ID.BTN_UP); Buttonup.setonclicklistener (NewButton.onclicklistener () {@Override Public voidOnClick (View v) {dismiss (); Listener.refreshpriorityui ("data from: Top");    }        }); }}

Mainactivity Code:

 Public classMainactivity extends Activity {@Override Public voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.main); Button Button=(Button) Findviewbyid (R.ID.BTN); Button.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {popupdialog Popupdialog=NewPopupdialog (mainactivity. This, R.style.dialog,NewPopupdialog.prioritylistener () {@Override Public voidRefreshpriorityui (Stringstring) {Toast.maketext (mainactivity. This,string, Toast.length_short). Show ();                }                }); Popupdialog.setcanceledontouchoutside (true);//Click the area outside the dialog dialog box to disappearwindow window =Popupdialog.getwindow (); Windowmanager.layoutparams LP=window.getattributes (); LP.Y= - -;//set the offset in the vertical directionLp.dimamount = 0f;//the background is not dimmed when the dialog box pops uppopupdialog.show ();    }        }); }}

Final effect:

After clicking on, Mainactivity will call the Refreshpriorityui () method:

dialog data transfer to activity

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.