2013-05-12 179 views
-1

您好我的片段活動我可以控制,我想我的片段是作爲下面哪一頁去另一個片段,而在片段

mIndicator.setCurrentItem(mAdapter.getCount() - 1); 

但在我的片段,我想進入另一個我已經意識到這個代碼不起作用有沒有解決這個問題的方法?

+0

你想提出的是,讓你從一個片段移動到另一個(初始片段不可見)或在第一個片段上打開第二個片段? – zabawaba99 2013-05-12 16:20:53

回答

0

請您在提問時更具體一些。當我們不知道如何編寫代碼時,很難回答。

首先,您必須閱讀以下內容:http://developer.android.com/guide/components/fragments.html,將向您介紹Android中片段的基礎知識。

無論如何,如果我理解正確,您需要一個FrameLayout,以符合法案。下面的例子:

<FrameLayout 
    android:id="@+id/frameLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" /> 

其次,在Java代碼中,你需要輸入:

Fragment mfragment = new yourDummyFragment(); 

FragmentManager fragmentManager = getSupportFragmentManager(); // The support android library 
FragmentTransaction mtransaction = fragmentManager.beginTransaction(); // Initialize the transaction 
mtransaction.replace(R.id.xmlOfYourFragment, mfragment); 
mtransaction.commit(); // The change starts.