-1

嗨,在我的片段活动中,我可以控制我希望片段位于哪个页面,如下所示

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

但是在我的片段中,我想进入另一个片段,我已经意识到这段代码不起作用,这个问题有什么解决方案吗?

4

1 回答 1

0

Please, be more specific when you ask a question. It's difficult to answer when we don't know how is written your code..

First of all you MUST read this: http://developer.android.com/guide/components/fragments.html, will teach you the basics of fragment in Android.

Anyway, if I understand correctly, you need a FrameLayout, to fit the bill. Below the example:

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

Secondly, in your Java code, you need to type this:

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.
于 2013-05-12T17:30:31.600 回答