Replace fragment in tab

Refresh

November 2018

Views

336 time

2

I am trying to implement an Action Bar with Tabs navigation set using ActionBarSherlock. I currently have three tabs which I can switch between ok. On one of my tabs I am implementing a ListView. When one of the items in the list is selected I want to replace the list with another fragment which will be a detail view of the selection.

When I call the FragmentTransaction.replace method with the new detail fragment I can see the new fragment appear but it overlaps the ListView, meaning I can see both fragments. Is this kind of navigation possible using the ActionBar tabs navigation, or am I on completely the wrong lines. I feel I am missing something really fundamental here.

I have a SherlockFragmentActivity which is implementing a TabListener to handle moving between tabs. The fragment hosting the ListView inherits from SherlockListFragment and I have attached a OnItemClickListener to respond to the tap and to replace the fragment. I am using this code

numbersList.setOnItemClickListener(new ListView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> a, View v, int i, long l) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(android.R.id.content, new NumberSelectedNavigationMenuFragment());    
        ft.commit();    
    }
});

The fragment which is replacing the ListView is currently just a basic LinearLayout with a TextView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Test"
            android:id="@+id/textView"/>
</LinearLayout>

Any help appreciated with this as I am well and truly stuck ...

0 answers