Calling a method in one fragment from another

FragmentManager fm = getFragmentManager(); 
MainFragment fragm = (MainFragment)fm.findFragmentById(R.id.main_fragment); 
fragm.otherList(); 

This code worked best for me. And seems quite easy


In MainFragment class you can do the following code:

private static MainFragment instance = null;

@Override  
public void onCreate(@Nullable Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    instance = this;  
}

public static MainFragment getInstance() {  
    return instance;  
} 

And in SocialMedia class you can call the method as follows:

MainFragment.getInstance().otherList();