How to call fragment method from main activity
问题 I have method in fragment class. I want to call that method from main activity but I don't want to use FragmentById (or) FragmentByTag. My fragment method: public void setItemFromDrawer(String sourceTag, String destTag) { //dosomething } How to call above method from main activity without using FragmentById (or) FragmentByTag? 回答1: First create an interface public interface MyInterface { void myAction() ; } Your fragment must implement this interface. public MyFragment extends Fragment