Reputation: 567
I want to use a custom date and time picker in my code for that i created a seperate package and put all the date and time picker classes there. The code is running smoothly if i'm running it from main activity but when i want to call from a fragment it's not recognizing getSupportFragmentManager() method the call which i'm making from my fragment is :
SimpleDateTimePicker simpleDateTimePicker = SimpleDateTimePicker.make(
"Set Date & Time Title",
new Date(),
this,
getSupportFragmentManager()
);
simpleDateTimePicker.show();
Please help, thank you guys.
Upvotes: 0
Views: 12684
Reputation: 2306
This is working for me
getBaseActivity().getFragmentManager()
Try it.
Upvotes: 0
Reputation: 10881
looks like SimpleDateTimePicker
class is your own class, which accepts only android.app.FragmentManager
, not android.support.v4.app.FragmentManager
. So you can use that class only with API11 or higher. If you want to use android.support.v4.app.FragmentManager
, you need to edit your SimpleDateTimePicker
to accept that android.support.v4.app.FragmentManager
in constructor
EDIT:
ok, there are 2 different classes: android.app.FragmentManager
and android.support.v4.app.FragmentManager
. The second one is a compatibility implementation of the first one. Most apps use the second, as it allowed to be used before API 11. And the class from your link uses the first one. There are two ways to fix it:
1st - you start using android.app.FragmentManager
instead of android.support.v4.app.FragmentManager
. It will cause app work only above api 11.
2nd way is changing code of SimpleDateTimePicker
to use android.support.v4.app.FragmentManager
. It is more correct way I think.
Upvotes: 0
Reputation: 567
Firstly check your frgaments
extends from android.support.v4.app.Fragment
or android.app.Fragment
.If it is android.app.Fragment
then call getActivity().getFragmentManager();
or if it extends from support frgament
then call getActivity().getSupportFragmentManager();
Upvotes: 0
Reputation: 2793
You don't.
You need to call getChildFragmentManager()
from the Fragment. Attempting to call getActivity().getSupportFragmentManager()
will throw an error.
Upvotes: 0