0
我在FragmentTransaction.replace(id, fragment, 'string')
很難理解什麼呢.replace
實際上不能理解片段取代
我讀的地方,它會與片段,但在我
public class MainActivity extends
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (findViewById(R.id.fragment_container) !=null) {
if(savedInstanceState!=null){
return ;
}
ArticleFragment first_fragment = new ArticleFragment();
HeadlineFragment second_fragment = new HeadlineFragment();
first_fragment.setArguments(getIntent().getExtras());
second_fragment.setArguments(getIntent().getExtras());
FragmentTransaction manager=getSupportFragmentManager().beginTransaction();
manager.add(R.id.fragment_container, first_fragment,"first");
manager.add(R.id.fragment_container, second_fragment,"second");
manager.commit();
}
abc newFragment = new abc();
Bundle args = new Bundle();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newFragment,"second");
transaction.addToBackStack(null);
transaction.commit();
}
}
更換視圖id的內容,只替換第一片段,我添加到Transaction
,即first_fragment
。
我如何替換特定的片段?
是不是ID *** *** R.id.fragment_container有指定添加片段的位置? – DarkCoderRises 2015-04-03 14:10:32