2012-03-29 18 views
0

我想改变我的片段(Fragment1)类源名称,当我点击另一个片段(Fragment2)中的按钮。 我Fragment2加入这一行:instanciate一个新类名片段

Fragment1.instantiate(getParent(), "com.infrabel.railtime.fragments.MyTitleFragment"); 

不过,这并不改变片段1的内部!

我的代码有什么问题?

回答

1

我不认为这些片段是用来做你想要做的。这似乎是你真正想要的是执行片段交易,删除片段1和“fragment3”,这是MyTitleFragment,喜欢在这个例子中从Fragment文档demo'd补充说:

// Create new fragment and transaction 
Fragment newFragment = new ExampleFragment(); 
FragmentTransaction transaction = getFragmentManager().beginTransaction(); 

// Replace whatever is in the fragment_container view with this fragment, 
// and add the transaction to the back stack 
transaction.replace(R.id.fragment_container, newFragment); 
transaction.addToBackStack(null); 

// Commit the transaction 
transaction.commit();