ActionBarSherlock, ViewPager, TabsAdapter nested Tab Fragments

前端 未结 1 1718
孤城傲影
孤城傲影 2021-01-04 22:59

I implemented a ActionBarSherlock with a ViewPager and a TabsAdapter. It works well but now I tried to \"push\" from a Framework Loaded in \"Tab 1\" another Fragment.

<
相关标签:
1条回答
  • 2021-01-04 23:56

    I gotcha!

    Let me explain, you need to put an id on your Layout that you want to replace, my example:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/Framelay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
        <TextView
            android:id="@+id/txtSearchTopic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="TextView" />
    
    </FrameLayout>
    

    So I just put mine: android:id="@+id/Framelay" Then I can use this Id to replace for the new fragment, what I mean is that all the content inside this Layout will be replaced by the new Fragment, as I called DetailFragment.

    FragmentManager fragmentManager = getFragmentManager();  
    FragmentTransaction fragmentTransaction = fragmentManager  
            .beginTransaction();  
    DetailFragment fragment3 = new DetailFragment();  
    fragmentTransaction.replace(R.id.Framelay, fragment3);  
    fragmentTransaction.commit(); 
    
    0 讨论(0)
提交回复
热议问题