As title, I used ActionBarSherlock and SlidingMenu on my APP.
To add menu item on actionbar, what I did is:
public class Main extends SherlockFragmentActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Sherlock);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getSupportActionBar();
setContentView(R.layout.main);
FragmentManager fm=getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
menuFrag=fm.findFragmentByTag("f1");
if(menuFrag==null)
{
menuFrag=new MenuFragment();
ft.add(menuFrag, "f1");
}
ft.commit();
//...other stuff
}
/**
* A fragment that displays a menu. This fragment happens to not
* have a UI (it does not implement onCreateView), but it could also
* have one if it wanted.
*/
#SuppressLint("ValidFragment")
public class MenuFragment extends SherlockFragment
{
public MenuFragment(){}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
itemProgram=menu.add(0, MENU_ID_PROGRAMS, 0, getString(R.string.menuProgram));
itemProgram.setIcon(R.drawable.icon_programs_select).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
itemMyList=menu.add(0, MENU_ID_MYLIST, 0, getString(R.string.menuMyList));
itemMyList.setIcon(R.drawable.icon_mylist).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
itemPlaying=menu.add(0, MENU_ID_PLAYING, 0, getString(R.string.menuPlaying));
itemPlaying.setIcon(R.drawable.icon_playing).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
}
}
In most time it runs well, but sometime I'll get this error when I start my APP
android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment
make sure class name exists, is public, and has an empty constructor that is public
And my APP just crashed...
To follow that error message, I did add an empty constructor on MenuFragment, but my APP sometime still force closed by same error.
I also read some thread about this in StackOverflow, but just not understand enough.
What can I do to overcome this problem ?
OK, I finally fixed this by using this
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
itemProgram=menu.add(0, MENU_ID_PROGRAMS, 0, getString(R.string.menuProgram));
itemProgram.setIcon(R.drawable.icon_programs_select).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
itemMyList=menu.add(0, MENU_ID_MYLIST, 0, getString(R.string.menuMyList));
itemMyList.setIcon(R.drawable.icon_mylist).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
itemPlaying=menu.add(0, MENU_ID_PLAYING, 0, getString(R.string.menuPlaying));
itemPlaying.setIcon(R.drawable.icon_playing).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return super.onCreateOptionsMenu(menu);
}
instead of this
public class MenuFragment extends SherlockFragment
{
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
//Some stuff...
}
}
And fixed my problem.
Related
I have two support fragments sitting inside an AppCompatActivity. By design they each have unique Toolbar and Option Menus. The AppCompatActivity does not have a toolbar in it's layout as these are included in each fragment.
In each fragment, I setHasOptionsMenu(true); in onCreate().
In onCreateView() I am calling ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar); where toolbar is the object bound to the xml Toolbar element.
In onCreateOptionsMenu(), I first make the call to super, then I call menu.clear() and finally inflate the menu with inflater.inflate(R.menu.searchbar_menu, menu);
Where this fails is in calling ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar); in both fragments. In doing so, the options will only appear on the second fragment and not on the first. If I call it in only one fragment, the options appear as expected in only that one fragment. Of course, if I call it in neither, they do not appear at all.
Here is my code. Both Fragments are essentially identical with the exception of the menus inflated:
public class FeedFragment extends Fragment implements FeedView{
#BindView(R.id.toolbar)
Toolbar toolbar;
FeedPresenter presenter;
static final String TAG = "FEED_FRAGMENT";
/*
* Some boilerplate fragment setup code
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_feed, container, false);
ButterKnife.bind(this, view);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
setupToolar();
return view;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.searchbar_menu, menu);
}
private void setupToolbar(){
toolbar.setPadding(0,ScreenUtil.getStatusBarHeight(this.getActivity()),0,0);
toolbar.setTitle("");
}
/*
* Other logic code unique to each fragment
*/
Does anyone know has I can set both fragments to have their toolbar options?
Thanks in advance.
When you call getActivity(), it returns the same instance of your Activity. The second fragment was initialized later than the first fragment, that why the Activity can only support action bar on the second fragment.
You could try this
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
AppCompatActivity baseActivity = (AppCompatActivity) getContext();
baseActivity.setSupportActionBar(yourToolbar);
}
}
What worked for me was setting suppoerActionBar according to which fragment is currently visible. You can use the following code:
#Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
if(!hidden){
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
}
}
I'm working to implement a SearchView on my Fragment's RecyclerView as shown here. When the user taps the search button I want the Menu Item for the SearchView to Override the toolbar and display the area for them to search. If I don't use my custom style for the toolbar it works fine but when I do it get the images below.
Here is what I am currently getting:
This is the class that the EventListActivity inherits from:
public abstract class SingleFragmentActivity extends AppCompatActivity {
protected abstract Fragment createFragment();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventcalendar_activity_fragment);
// Manages our fragments. We can call it to add a fragment to an activity in code
FragmentManager fm = getSupportFragmentManager();
// Check if fragment of R.id already exits
// The FragmentManager saves out the list of fragments on rotation destruction or memory reclaim
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
// If the the fragment does not exist, create it
if(fragment == null) {
fragment = createFragment();
// Create a new fragment transaction, include one add operation in it, and then commit it
fm.beginTransaction().add(R.id.fragment_container, fragment).commit();
}
}
}
This creates the fragment that manages and works with the RecyclerView:
public class EventListActivity extends SingleFragmentActivity {
#Override
protected Fragment createFragment() {
// Setting arguments for the new fragment created from the intent from EventFeedResultWrapper
EventListFragment fragment = new EventListFragment();
fragment.setArguments(getIntent().getExtras());
return fragment;
}
}
Fragment that holds the RecyclerViewthat the SearchView will interface with. This is where the search menu button is inflated. It is where I've been trying to modify the toolbar:
public class EventListFragment extends Fragment {
private RecyclerView mEventRecyclerView;
private EventAdapter mAdapter;
// Telling the FragmentManager that it is
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
((AppCompatActivity)getActivity()).getSupportActionBar().setCustomView(R.layout.action_bar_center);
View sabView = ((AppCompatActivity)getActivity()).getSupportActionBar().getCustomView();
TextView titleTxtView = (TextView) sabView.findViewById(R.id.action_bar_title);
titleTxtView.setText("Events Calendar");
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowCustomEnabled(true);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.eventcalendar_fragment_event_list, container, false);
mEventRecyclerView = (RecyclerView) view.findViewById(R.id.event_recycler_view);
// RecyclerView requires a layout manager to work, layout manager is in charge of position items on screen
mEventRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
updateUI();
return view;
}
// Populate the menu instance
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.eventcalendar_menu, menu);
}
// When we edit a EventActivity this saves it back to the EventListActivity
// onResume over onStart because we cannot assume the activity will be stopped
// when another activity is in front of it. If the other activity is transparent
// then the activity might just get paused. If it is paused then onStart() will not be called
// but on resume will be called.
// NOTE: In general onResume() is the safest place to take action to update a fragment's view
#Override
public void onResume() {
super.onResume();
updateUI();
}
private void updateUI() {
// Read in the events saved in to EventFeedResultWrapper by the Async task in ParseEventFeedTask
EventFeedResultWrapper wrapper = (EventFeedResultWrapper) getArguments().getSerializable(ParseEventFeedTask.EXTRA_RESULTS_LIST);
// Make sure wrapper is not null, it will NEVER be null
if(wrapper == null){
throw new RuntimeException("Error: The wrapper is null!");
}
// Get all the events from the wrapper/serializable
List<Event> events = wrapper.getEventFeedResults();
// Gets the context that we don't use rofl
EventCal eventCal = EventCal.get(getActivity());
// Add all the events we got from the wrapper to our event manager eventCal
eventCal.addEvents(events);
// Check to see if the EventAdapter is already setup
if(mAdapter == null) {
mAdapter = new EventAdapter(events);
mEventRecyclerView.setAdapter(mAdapter);
} else {
mAdapter.notifyDataSetChanged();
}
}
//Adapter here - removed code since it doesn't do anything with the toolbar
//RecycleView onClickLister - removed code since it doesn't do anything with the toolbar
}
This is the custom XML Style
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/action_bar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:textSize="24dp"/>
</LinearLayout>
Event Menu XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search"
android:title="Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always"/>
</menu>
Did you missed android:orientation="vertical". The text is displaying vertically. You want horizontal right?
Oh nvm i didn't understood it at first. The problem must be the inflating of the custom view, for some reason it seems it keeps the original view there and inflated it somewhere else. Give me 1s i'll update the answer when i find the issue
Check here: getSupportActionBar().setCustomView(view) does not fill entire actionbar
Similar problem. First and Second answer
EDIT2: Remove the code from EventListFragment onCreate. You don't need to inflate a searchView, you can use the default one.
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_main, menu);
super.onCreateOptionsMenu(menu, inflater);
setOptionsMenu(menu);
}
public void setOptionsMenu(Menu menu) {
MenuItem search = menu.findItem(R.id.search);
SearchView searchView;
/**
* Setup the SearchView
*/
SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
final boolean[] modifiedOriginal = {false};
searchView = (SearchView) search.getActionView();
if (searchView != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(((Activity) context).getComponentName()));
MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
...
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
...
return true;
}
});
final EditText et = ButterKnife.findById(searchView, android.support.v7.appcompat.R.id.search_src_text);
et.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
String s = editable.toString();
if (!s.equals("") && !s.equals(" ")) {
...
}
}
});
ButterKnife.findById(searchView, android.support.v7.appcompat.R.id.search_close_btn).setOnClickListener(
view -> {
...
et.setText("");
}
);
}
}
You can leave your menu xml as it is.
I have Action Bar in my application. I am adding action items using menu.xml. I am using action bar-compat as my support library. I observed a weird issue where my action items are getting duplicated.
I am finding this issue randomly when leave my device idle or work with other applications. Please find the screen shot and my code below:
private LoginWebActivity mContext;
private final String TAG = "LoginFragment";
// for metrics
private String mPageNameSignIn = "signin";
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.webview, container, false);
return mView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mContext = (LoginWebActivity) getActivity();
initFragment();
}
#Override
public void onResume() {
super.onResume();
}
/**
* Initialises the views and variables of the fragment.
*/
#SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
protected void initFragment() {
mWebView = (WebView) mView.findViewById(R.id.webView);
Bundle b = mContext.getIntent().getExtras();
if (b != null) {
mUrl = b.getString(Constants.EXTRA_WEB_LOGIN_URL);
}
super.initFragment();
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.signin, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Navigate
switch (item.getItemId()) {
case R.id.menu_item_signup:
mContext.onSignUpClick();
break;
case android.R.id.home:
if (!goBack())
getActivity().finish();
default:
break;
}
return super.onOptionsItemSelected(item);
}
My XML :
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/menu_item_signup"
allergy:showAsAction="ifRoom"
android:title="#string/sign_up">
</item>
You must clear your menu object before adding items. I had the same problem and this was the best solution that I've found.
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.signin, menu);
super.onCreateOptionsMenu(menu, inflater);
}
Pretty late to this party, but for anyone that comes across this via the Google like I did, here's the real problem.
You didn't post your Activity code that's creating the Fragment, but I will venture to guess that it looks something like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
Fragment fragment = ...
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
}
The problem with this is that when the activity goes through its lifecycle (which would happen "when leave my device idle or work with other applications", as you say), the system will save and restore the state of fragments for you. But with this code, you also are adding a new fragment to your Activity, so you end up with multiple fragments running in your activity, each adding an item to the menu.
While the posted workaround will address the duplicate menu entries issue, it would leave these extra fragment instances lying around, which is obviously not what you want.
The correct fix is a simple null check:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
if (savedInstanceState == null) {
Fragment fragment = ...
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
}
}
Since the system will indicate the activity is being recreated with a non-null Bundle for the savedInstanceState parameter, you check this to determine whether you should be creating and adding a new fragment.
Hope that helps.
i used Renan Bandeira's great solution and i had some error so i changed it a little bit and worked for me too . then I'm sharing my experience : maybe it become helpful again all credit goes to him for great solution .
#Override
public void onCreateOptionsMenu(Menu menu ) {
menu.clear();
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu."your current activity name ", menu);
return true;
}
I facing the same problem and exactly as state by #Szymon "I add menu option from the fragment, I create multiple fragments?" So my solution was look like below.
onCreate :
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.menu, menu);
menu.findItem(R.id.action_one).setVisible(true);
menu.findItem(R.id.action_two).setVisible(false);
super.onCreateOptionsMenu(menu, inflater);
}
onPrepare :
#Override
public void onPrepareOptionsMenu(Menu menu) {
if (isAdded()
&& !isDetached()
&& isVisible()
&& !isRemoving()
)
{
// show the menu
if (menu.findItem(R.id.action_one).isVisible())
menu.findItem(R.id.action_one).setVisible(true);
// hide the menu
if (menu.findItem(R.id.action_two).isVisible())
menu.findItem(R.id.action_two).setVisible(false);
}
}
You should use the following method instead and you will not see the duplicates anymore (notice that it has only a Menu object as argument)
#Override
public boolean onCreateOptionsMenu( Menu menu )
{
getMenuInflater().inflate( R.menu.main_activity_menu, menu );
return true;
}
Is it permitted to call SherlockFragmentActivity.supportInvalidateOptionsMenu from SherlockFragment.onCreateView? I couldn't find anything saying otherwise, but it seems like doing so may cause clicks on the menu items to not be handled until one exits the activity. (This happens on an API 8 emulator).
I have a fairly simple repro of this behavior. For some reason, it only happens when the activity did not add any menu items, but the fragment did.
Following is the code of the repro, if anyone is interested. What will happen is, the background will not turn red. However, if you comment out getSherlockActivity().supportInvalidateOptionsMenu(), it does turn red.
public class MainActivity extends SherlockFragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frag_container);
FunFragment frag = new FunFragment();
FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.add(R.id.frag_container, frag, "foobar");
trans.commit();
}
}
public class FunFragment extends SherlockFragment {
#Override
public void onActivityCreated(Bundle savedInstanceState) {
setHasOptionsMenu(true);
super.onActivityCreated(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getSherlockActivity().supportInvalidateOptionsMenu();
return new View(getActivity());
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(0, 5, 0, "Do magic").setIcon(R.drawable.ic_launcher)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 5:
getView().setBackgroundDrawable(new ColorDrawable(0xFFFF0000));
return true;
default:
return false;
}
}
}
You can just call invalidateOptionsMenu() instead of supportInvalidateOptionsMenu().
So I've been working on and Android app that has a Navigation Bar on the top with several Tabs, and that part is working fine but now I want to be able to dynamically add Menu Items to the Action Bar from different Fragments (since some Fragments may have different options available). So far no matter what I've tried I can't seem to get the onCreateOptionsMenu to be called. Here's what I have so far
//First I have a holder class that is used to navigate between the different Fragment Tabs
public class ActionHolder extends SherlockFragmentActivity implements ActionBar.TabListener {....
//And then I have this method for switching Fragments based on what Tab is selected
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
int selectedTab = tab.getPosition();
if (selectedTab == 0) {
SalesMainScreen salesScreen = new SalesMainScreen();
ft.replace(R.id.content, salesScreen);
}
else if (selectedTab == 1) {
ClientMainScreen clientScreen = new ClientMainScreen();
ft.replace(R.id.content, clientScreen);
}.....
Now here is one of the Tab's Fragments (the SalesMainScreen) that I want to have a few menu items added to the Action Bar
#Override
public void onCreate (Bundle savedInstanceState) {
Log.i("message","the oncreate method was called");
setHasOptionsMenu(true);
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved) {
return inflater.inflate(R.layout.salesmainscreen, group, false);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.i("message", "the oncreatemenu method called");
inflater.inflate(R.menu.menu_refresh, menu);
super.onCreateOptionsMenu(menu, inflater);
}
I see the OnCreate Log message being called but I don't see the onCreateOptionsMenu Log being called at all. Also, I know that sometimes the imports cause issues, but when I import the Sherlock Menu and Menu Inflater I get all kinds of error messages on the OnCreateOptionMenu method about them not being compatible. Is it possible in this setup to dynamically add Menu Items to the Action Bar, or should I just add the items and then just don't do any actions on the ones that don't apply to the fragment that is being displayed?
I have an app using SherlockActionBar and tabs, with each tab containing a SherlockFragment. The main activity has its own menu in the action bar, and one of the fragments adds a search item to the action bar menu.
The main activity has the following:
class MainActivity extends SherlockFragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ActionBar bar = getSupportActionBar();
bar.addTab(createThingOneTab());
bar.addTab(createThingTwoTab());
bar.addTab(createThingThreeTab());
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
}
}
The fragment in the tab has the following:
class ThingOneFragment extends SherlockFragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem search = menu.add("Search");
search.setIcon(android.R.drawable.ic_menu_search);
search.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
...
}
}
When I start the main activity, the tab shows ThingOneFragment by default and I see the search icon in the action bar. When I select the other tabs, the search icon disappears. You do need to make sure that you are using the Sherlock classes for Menu, MenuInflater, etc.
I'm not sure if it makes a difference but my TabListener looks like this:
private TabListener createTabListener(final Class<? extends Fragment> clazz) {
return new TabListener() {
private Fragment mFragment;
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// no action
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(activity, clazz.getName());
}
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, mFragment)
.commit();
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// no action
}
};
I'm not sure if that is causing your issue or if it's even the correct way of handling tabs but I include it for completeness.