上課

2016-04-05 34 views
0

我一直使用FragmentTransaction在我的一個項目來設定初始片段上課

//Set the fragment initially 
MainFragment fragment = new MainFragment(); 
android.support.v4.app.FragmentTransaction fragmentTransaction = 
    getSupportFragmentManager().beginTransaction(); 
fragmentTransaction.replace(R.id.fragment_container, fragment); 
fragmentTransaction.commit(); 
toolbar = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 

但現在使用類即時通訊,我想設置一個初始XML顯示一個類的運行Java fragmentTransaction。我將如何做到這一點。感謝

+0

能否請您解釋一下嗎? 片段已經是類。 – Ian

回答

2

如果你的意思是類的活動,你可以使用

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.your_layout); 
}