android - Passing data from dialogfragment to fragment -


i got activity 3 fragments , 1 of these fragments i'm calling mydialogfragment.show()-method. dialog appears, text-input , try pass text-input fragment. far good.

i set back-communication via onactivityresult() of 'parent'-fragment in combination set/gettargetfragment()-calls (see code below). , result in parent-fragment, cannot pass data. every attemp create intent , putting extra-data in fails. don't know if blind or such.. shouldn't able create intent inside onclick()-method?!

any appreciated!

inside dialog-fragment:

public dialog oncreatedialog(bundle savedinstancestate) {     alertdialog.builder builder = new alertdialog.builder(getparentfragment().getactivity());     layoutinflater inflater = getactivity().getlayoutinflater();     builder.setview(inflater.inflate(r.layout.dialog_choose_title, null));      builder.settitle(mtitle)             .setpositivebutton(r.string.dialog_save_title, new dialoginterface.onclicklistener() {                 @override                 public void onclick(dialoginterface dialog, int which) {                     intent intent = new intent(getparentfragment().getactivity(), mymainclass.class);                     intent.putextra("title", medittext.gettext().tostring());                     gettargetfragment().onactivityresult(gettargetrequestcode(), activity.result_ok, intent);                     dismiss();                 }             })             .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() {                 @override                 public void onclick(dialoginterface dialog, int which) {                     dismiss();                 }             });     return builder.create(); } 

inside fragment:

public void onclick(view v) {             choosetitledialog dialog = choosetitledialog.newinstance(mtimerobject.getmtitle());             dialog.settargetfragment(mthis, 42);             dialog.show(mfragmentmgr, "choose_title_dialog");         } 

and little blind! while creating intents , thinking right context (getactivity(), getparentfragment().getactivity(), ...) or other possibilities create callbacks fragment did not waste second thinking other reasons error. edittext-element try text (medittext) not initialised :\

some modification make work:

view v = inflater.inflate(r.layout.dialog_choose_title, null); medittext = (edittext) v.findviewbyid(r.id.id_edit_choose_title); medittext.settext(mtitle); builder.setview(v); 

thanks time gokhan!


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -