Using FragmentManager to access fragment methods from activity

In the method below, I am trying to call the fragment method from within an action. Class this method in extends FragmentActivity. Should my import for fragments from android.support.v4? An error on the last line of “Unable to drop from fragment in NasaDailyImage” any ideas?

  public void onRefresh(View view){
       android.app.FragmentManager fragmentManager=getFragmentManager();
       NasaDailyImage NasaDailyFragment;
       NasaDailyFragment=(NasaDailyImage)fragmentManager.findFragmentById(R.id.fragment_iotd);  //cannot cast from Fragment to NasaDailyImage

 //NasaDailyFragment.onRefresh();
   }

Currently, all my import data for fragments belongs to android.support.v4.app, with the exception of FragmentManager, because when I import the file android.support.v4.app.FragmentManager instead of android.app.FragmentManager, then the getFragmentManager () method is bigger not available. I tried to work around this by creating the android.support.v4.app.FragmentManager () object, but I got an error saying that I cannot create it.

+5
source share
1 answer
+9
source

All Articles