Android send Data from fragment to Activity -
i'm working on android app, datas in fragment , want use them in other fragment. looking create bundle, in activity simple getbasicinfos() method return bundle send other fragment. problem can't use method in activity.
fragment = new dashboardfragment(); fragment.getbasicinfos(); //does not recognize method toolbar.settitle(getresources().getstring(r.string.dashboard)); break;
i want know if there better way, or more simple.
create interface
in fragment
, implement interface in activity
while instantiating fragment = new dashboardfragment(this);
pass listener , in fragment constructor
save this
public dashboardfragment(fragmentlistener listener) { this.listener = listener; }
and use listener pass data activity
.
hope helps.
Comments
Post a Comment