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.
Related
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'm creating a swipeable Sherlock tab. I used this tutorial to do it:
Android ActionBarSherlock ViewPager Tabs Tutorial
However when I want to start an activity from inside of a fragment (for example FragmentTab1) I need context to create intent and start activity.
I'm in the Fragment class and don't have access to context!
I can't use getActivity() too, because FragmentTab1 is created inside of getItem() function in FragmentPagerAdapter class.
What should I do?!
Sherlock Fragments works with getSherlockActivity() instead of getActivity()
You should try using
getSherlockActivity().startActivity(...)
I'm in the Fragment class and don't have access to context!
Yes, you do. Call getActivity() to return the Activity that is hosting this fragment. Activity inherits from Context.
I can't use getActivity() too, because FragmentTab1 is created inside of getItem() function in FragmentPagerAdapter class.
So? That does not somehow magically cause the getActivity() method to vanish.
For some reason, you are using ActionBarSherlock, which has been deprecated for about 20 months by its author. If your fragment is a SherlockFragment, you will want to call getSherlockActivity() instead.
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!
In MainActivity.java, I extends TabActivity to use Tabhost.
public class MainActivity extends TabActivity
In each Tab, I use ActivityGroup to manage some child activity
public class MerchandiserTabGroupActivity extends ActivityGroup
In a child activity A, I want to start another child activity B.
Intent intCreateClaim = new Intent(mContext, MultiPhotoSelectActivity.class);
startActivityForResult(intCreateClaim, Parameter.ACTIVITY_SELECT_IMAGE);
After I call setResult(RESULT_OK) and finish() in Activity B, onActivityResult() in Activity A isn't called.
Can anyone helps me? Thanks in advance.
I know this isn't really the answer you're looking for, but you're using deprecated API. You should try a refactor and use the new Fragment API and the v4 support library if you need to support older versions of Android too. Using fragments you won't need to rely on setResult and onActivityResult.
Fragment
Fragment Tab Host
This happens because after B activity finishes, Android returns to your TabActivity, not your A activity.
Use fragments. This way you will not have to deal with multiple activities. You will have only one parent activity with fragments inside. To make your life easier and to add support for pre-ICS Android devices, try GrilledUI library.
hi i've an app where i want to implement setVolumeControlStream
but i can't because my class extends TabActivity not Activity. what shall i do ??
setVolumeControlStream() is available on TabActivity, because TabActivity inherits from Activity.