java - android fragment control main activity -
i have app working fragment called main activity. works great able control menu above fragment layout.
so lets navigate fragment blog posts text view set in menu above fragment update or hide button or show button set visibility.
i have no clue how control things not in current fragment.
how should go this.
thanks
define interface in fragment , have activity implement interface.
public interface myinterface { // add methods here }
in onattach, interface:
@override public void onattach(activity activity) { super.onattach(activity); if (activity instanceof myinterface) { mmyinterface = (myinterface) activity; } else { throw new classcastexception(activity + " must implement interface myinterface"); } } @override public void ondetach() { mmyinterface = null; super.ondetach(); }
then call mmyinterface methods needed.
Comments
Post a Comment