Fragmentation and action bar sherlock - android

I am using sherlock action bar API for action bar implementation,My problem is
I am using fragmentation in android.my main activity class is using more then 3
fragments to display things now I need to access that action bar in every fragment
but whenever I moved from main activity to any other fragments action bar is not
accessible there. when ever I call any action it gives my null pointer exception kindly need your help.

Be sure that other fragments are extending SherlockFragment
And then call this method:
this.getSherlockActivity().getSupportActionBar().setTitle(TheString);

if I understand the question, you need to reach the actionbar from the fragment inside an activity. So once you reach the activity from the fragment, from there you can get the actionbar. say that you need to set the title:
from the fragment (it should be a SherlockFragment) do the following
getSherlockActivity().getSupportActionBar().setTitle(theTitle);

Related

Split actionbar for a specific fragment

I have an activity with three fragments. Fragment A has 1 item in actionbar. Fragment B has 4 items in actionbar, and Fragment C has 1. So, I want to have split actionbar when I change to fragment B, but I don't want split action bar in A-C fragments, because there is no reason to fill de bottom of the screen with a bar only for one item.
Can I change actionbar mode when I change between fragments?
Not sure if this can be done using Fragments as ActionBar is associated with the Activity. However, I tried what you are looking for with two activities and it worked.
Add the action bar in onCreateOptionsMenu in both the activities and then add
getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
right before onCreate method of the activity in which you want the split action bar to appear. Thats it. Simple isn't it. :)
You can also hide and show it using getActionBar.hide() and getActionBar.show() methods respectively.
(The only thing I missed is checking this with support libraries. Will try and update you on that as well)
Let me know if this helps you in some way. Happy coding :)

How to hide the action bar (Sherlock) inside a Fragment?

I have an action bar set up in the main activity, and this creates a bunch of fragments. However, there are several fragments that require the action bar to be hidden, but I can't refer to the ActionBarSherlock class inside a fragment.
How can I hide the action bar?
Thanks for any suggestions.
Actually you can refer to ActionBar via activity which you can get from a SherlockFragment by calling SherlockFragment.getSherlockActivity(), then just call SherlockFragmentActivity.getSupportActionBar() and then hide()

Android Static title bar

I am trying to create an app that when you click through each page of the app the title bar doesn't move. I can create an xml with the same title bar but every time you go on to a new page the title bar disappears for a second and then reappears with the new page.
Does anybody have any suggestions/code that can help me with this?
Many Thanks
Take a look to Fragments. If you implement "each page of the app" as a separate Fragment - instead of Activity - then you can embed and switch these Fragments into the layout of the main Activity, obtaining what you need.
Use a tabActivity and have the activities inside it.
hide the tab bar as given here tab bar hiding issue android
Use mTabHost.setCurrentTabByTag to set the tab

Android same tab bar for all activities

well, I have my Android app that have 4 main options. For that I created a TabActivity with this options.
Problem, when I enter to one of this, a activity is called. Cool. Imagine I have a list and when I click on one row I open other activity, the tab will disappear what is correct. But I want this tabBar always.
how can I achieve this?
if I copy/page this tab in every activity I need it it will load the ones that are attached to the tab and wont show the one that I opened before, right?
You should try with FragmentActivity. There is a addTab function to add tabs to action bar, in which you set tabs. With fragments and action bar what you want to do is possible
Take a look at Action Bar Sherlock that includes actionbar compatibiliy with tabs and more for non Honeycomb versions of Android.

Fragments Within Fragment Tabs

I'm building an application that requires Tabs, which are now deprecated. The dev guide says to use Fragments to replace the tabs instead. However, my application needs to have fragments within each tab, which means fragments inside fragments, which isn't allowed. Does anyone know of a possible work around for this?
While the action bar support for tabs is designed to make it easy for the contents of a tab to be a fragment, that is not strictly required. You could use ViewFlipper, repeated calls to setContentView(), or something to arrange to change other stuff when the action bar tab is selected.
Prior to the native action bar (Android 1.x/2.x), either stick with classic tabs, or use something like Action Bar Sherlock to get an action bar and tabs.
I fake tabs by having a "tabs" fragment across the top that contains multiple toggle buttons. Below that I have a merge view containing a separate fragment for each tab.
I respond to taps on a toggle button by toggling the other buttons "off", showing the fragment for that "tab", and hiding the others.
its little late , but yes you can :) here's an example
but for fragment inside fragment inside tab isn't an android native way, you have to start a new fragmentActivity if you want to show detail of fragment. you can but is not an android way !

Categories

Resources