Fragment 추가 및 삭제 예제

|
void addLogViewerFragment() {
  logViewerFragment = new LogViewerFragment();
  FragmentManager fragmentManager = getSupportFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.add(R.id.logviewer_layout, logViewerFragment).commit();
}
  
void removeLogviewerFragment() {
  FragmentManager fragmentManager = getSupportFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.remove(logViewerFragment).commit();
  logViewerFragment = null;
}