android - How can i put Method in bundle to get invoke in other class -
i have fragment invoking dialog fragment , displaying it. want pass method defined in fragment dialog fragment .
i want know how can perform this? in bundle didnt see method pass method parameter, can pass parceable objects , lists.
i know callback system , interface can not think of work around achieve looking far.
bundle bundle = new bundle(); bundle.putstring("api_key","8cd52ec7-a4a9f43126d2"); bundle.putint("id",26); bundle.putwhat?(mymethod)..........> here problem
what tried:
i setting parameters in bundle want method send in bundle dialog fragment .
is possible ?
what other way of doing this??
just pass fragment instance dialog , access fragment public methods within dialog, instance:
fragment example
public class blankfragment extends fragment { public blankfragment() { // required empty public constructor } public static blankfragment newinstance() { blankfragment fragment = new blankfragment(); return fragment; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_blank, container, false); showdialog(); return v; } public void sharedmethod() { toast.maketext(getcontext(), "do whatever", toast.length_short).show(); } private void showdialog() { blankfragmentdialog dialog = new blankfragmentdialog(); dialog.blankfragment = this; dialog.show(getactivity().getsupportfragmentmanager(), ""); } }
fragment dialog example
public class blankfragmentdialog extends dialogfragment { public blankfragment blankfragment; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_blank, container, false); if(null != this.blankfragment) { this.blankfragment.sharedmethod(); } return v; } }
Comments
Post a Comment