I'm using CalendarDatePickerDialog from BetterPickers in my project,
if i use a FragmentActivity, then i can use the getSupportFragmentManager().
The problem is that i'm trying to add CWAC-Camera as well,
but for that i need to use
getFragmentManager() in a regular Activity which breaks the BettePickers.
any ideas?
Try to extends FragmentActivity and implements CalendarDatePickerDialog.OnDateSetListener
Change your Activity to FragmentActivity.
Use the newInstance(YouActivity.this)
Enjoy!
Related
I'm using AppCompatPreferenceActivity, that is an Activity which extends PreferenceActivity and has an AppCompatDelegate. I want to add a headless fragment to this Activity, but I can't call to getSupportFragmentManager...
Is there a way to add fragments to a PreferenceActivity using AppCompatDelegate?
The only way to call getSupportFragmentManager is from a FragmentActivity or something which derives from it. PreferenceActivity derives from Activity which cannot use Fragments.
You should look into using a PreferenceFragment instead.
Dear ladies and gents,
First of all, please do not mark my question down. If you think that my question is too stupid please let me know and i will edit it or remove.
So my actual question is that I have an activity (extends Activity). In that activity's layout I created FrameLayout where I then attach different four fragments(so each of them extends Fragment. So in one of that fragments I would like to implements swipeable tabs(see screenshot).
I know that it is usually done by implementing viewPager and FragmentPagerAdapter, but I can not do this as if I'm calling getSupportFragmentManager in my fragment it gives my an error. If i am using getActivity().getFragmentManager() it gives me error that android.support.v4.app.fragmentmanager cannot be applied to android.app.fragmentmanager. I have to use android.support.v4.app.fragment in my fragment, because otherwise I will not be able to implement my activity's view(described at the beggining).
Any ideas or suggestions would be very appreciated.screenshot
Make sure you are using Fragment class that you extends your fragments comes from support library. You also need to use FragmentActivity to call method getSupportFragmentManager();
On the other hand, viewpager which is in your fragment need to implemented as usual that you can find on internet except getChildSupportFragmentManager();
This one called "nested fragments".
PS: I am not sure but you can also use AppCompatActivity instead of FragmentActivity. FragmentActivity and ActionBarActivity must be deprecated.
Good luck
You can use getChildFragmentManager() when using Fragments inside other Fragments.
New version of Support Library v4 (Android 4.2) resolve this problem. For do this, simply do constructor of your custom FragmentPagerAdapter like this:
public CustomFragmentPagerAdapter(android.support.v4.app.Fragment fragment)
{
super(fragment.getChildFragmentManager());
// write your code here
}
This work because new Android version approve using nested Fragments
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.
You don't.
You need to call getChildFragmentManager() from the Fragment. Attempting to call getActivity().getSupportFragmentManager() will throw an error.
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();
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.
This is working for me
getBaseActivity().getFragmentManager()
Try it.
This worked for me:
getChildFragmentManager()
Toolbar mainly should used with ActionBarActivity
if I want to use it by Extends Activity it gives an error
when I call
setSupportActionBar(toolbar);
I main Above I don,t want to use ActionBarActivity
Any help here , And what About Another kind Of Activities
Like FragmentActivity or Others .
Example to support FragmentActivity
ActionBarActivity activity = (ActionBarActivity) getActivity();
activity.setSupportActionBar(toolbar);
If you're extending Activity just use setActionBar(). setSupportActionBar is for when your're using ActionBarActivity from the support library
You have done little mistake .. you had to extend
ActionBarActivity
not only
Activity
class ..when you do error will be removed.
How can I pass the getSupportFragmentManager() to external library in AccountAuthenticatorActivity?.
I need to put a custom dialog with android-styled-dialogs: https://github.com/inmite/android-styled-dialogs
Take AccountAuthenticatorActivity and put it in your project.
Instead of
AccountAuthenticatorActivity extends Activity put AccountAuthenticatorActivity extends FragmentActivity.
Extend your class with your new AccountAuthenticatorActivity and use getSupportFragmentManager().