I am trying to call methodToBeCalled() from my UnrelatedClass. I am new to fragments, and 5 days later, still cannot figure it out. I would greatly appreciate any detailed help! If I did not include necessary code, please let me know and I will happily post it! Thanks!
public class MainActivity extends FragmentActivity{
Fragment fragment = new FragmentActivity();
}
public class FragmentActivity extends Fragment{
methodToBeCalled();
}
public class UnrelatedClass{
//call FragmentActivity's methodToBeCalled() from here
//note it is not static
}
The method methodToBeCalled()
contains this code:
public void methodToBeCalled{
fragmentActivityTextView.setText("Something Else");
}
I have tried using this code in my UnrelatedClass, but unsuccessfully (althought I am not sure why):
if (MainActivity.getCurrentFragment() instanceof FragmentActivity) {
FragmentActivity fragment = (FragmentActivity) MainActivity.getCurrentFragment();
fragment.methodToBeCalled();