-1
每當我動態地添加片段它顯示主活動錯誤它不解決FragmentManger類。當我添加片段動態它顯示錯誤
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager=getFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
FirstFragment ff= new FirstFragment();
fragmentTransaction.add(R.id.fragment_container,ff);
fragmentTransaction.commit();
}
感謝您提前幫助..
使用getSupportFragmentManager()和片段。 –