android - Updating Parent Fragment from Child Fragment -
in android application, have 2 fragments. parent fragment contains list of available filter types , when particular filter type clicked (in parent fragment - yellow background) corresponding child fragment (pink background) opens list of available options selected filter type. requirement once user select/deselect option in child fragment, should reflect/update option count (green color) in parent fragment.
please check attached wireframe.
you can use otto bus comunications between fragments, fragments-activities, services, etc.
maybe, first time can little weird if have not used before powerful , easy use. can find library , tutorial here:
an example. in adapter or have item click event cand send object bus.
in bus invoque post method , pass object. (i recommended create singleton bus).
the singleton bus provider.
/** * canal de comunicacion */ public class busprovider { private static final bus rest_bus = new bus(threadenforcer.any); private static final bus ui_bus = new bus(); private busprovider() {}; public static bus getrestbusinstance() { return rest_bus; } public static bus getuibusinstance () { return ui_bus; } }
you send object in bus (in child fragment) this:
busprovider.getuibusinstance().post(itemselected);
and in parent fragment subscribe event:
@subscribe public void activityselected(final item itemselected) { }
hope helps you!!
Comments
Post a Comment