In the below method I'm trying to call a fragments method from within an activity. The class this method is in extends FragmentActivity. Should all my imports for the fragments be from android.support.v4? The error is on the last line "Cannot cast from Fragment to 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();
}
As of now all my imports for fragments are from android.support.v4.app except for the FragmentManager, because when I import android.support.v4.app.FragmentManager instead of android.app.FragmentManager then the getFragmentManager() method is no longer available. I tried to get around this by creating a android.support.v4.app.FragmentManager() object but I got an error saying that I cant instantiate it.
Did you try the public FragmentManager getSupportFragmentManager ()
method ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With