Q:

Using fragment in NavigationTab sample of ActionBarSherlock

I am trying to make the TabNavigation Sample in ActionBarSherlock works with going to different fragment, not just change the text of a textView (as we have in this sample). This is my code:
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.MenuItem;
import android.widget.Toast;

public class TestNavigation extends SherlockActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.Theme_Sherlock);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 1; i <= 3; i++) {
            ActionBar.Tab tab = getSupportActionBar().newTab();
            tab.setText("Tab " + i);
            SherlockFragment PlayerFragment = new PhotosActivity();
            tab.setTabListener(new MyTabsListener(PlayerFragment));
            getSupportActionBar().addTab(tab);
        }
    }

    class MyTabsListener implements ActionBar.TabListener {
        public SherlockFragment fragment;

        public MyTabsListener(SherlockFragment fragment) {
            this.fragment = fragment;
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            Toast.makeText(getApplicationContext(), "Reselected!", Toast.LENGTH_LONG).show();   
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.replace(R.id.fragment_container, fragment);
        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            ft.remove(fragment);
        }   
     }

And main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center">
    <LinearLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

 </LinearLayout>
</LinearLayout>

And photoActivity is very simple:
public class PhotosActivity extends SherlockFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.photos_layout, container, false);
    }   
}

could you help me?
If you think I am in the wrong way, please give me some sample or toturial that I can follow.

A:

Change your activity to extends SherlockFragmentActivity not SherlockActivity
and one more thing is to move ft.replace(R.id.fragment_container, fragment); to onTabSelected(Tab tab, FragmentTransaction ft) method and i don't think you need ft.remove(fragment); that is inside  onTabReselected() because it will remove your fragment if the tab is pressed while it is selected

