Code example for FragmentActivity

Methods: getSupportFragmentManager, setTitle

0
			initPrevButton(); 
		} 
	} 
 
	private void initTitle() { 
		setTitle(step.getTitleResId());
	} 
 
	private void initPrevButton() { 
		final WizardStep prevStep = flow.getPrevStep(step);
		if (prevStep == null) {
			prevButton.setVisibility(GONE);
			prevButton.setOnClickListener(null);
		} else { 
			prevButton.setVisibility(VISIBLE);
			prevButton.setOnClickListener(new View.OnClickListener() {
				@Override 
				public void onClick(View v) {
					if (tryGoPrev()) { 
						setStep(prevStep);
					} 
				} 
			}); 
		} 
	} 
 
	private void initNextButton() { 
		final WizardStep nextStep = flow.getNextStep(step); 
		if (nextStep == null) { 
			nextButton.setText(R.string.cpp_wizard_finish); 
			nextButton.setOnClickListener(new View.OnClickListener() { 
				@Override 
				public void onClick(View v) { 
					if (tryGoNext()) { 
						finishFlow(); 
					} 
				} 
			}); 
		} else { 
			nextButton.setText(step.getNextButtonTitleResId()); 
			nextButton.setOnClickListener(new View.OnClickListener() { 
				@Override 
				public void onClick(View v) {
					if (tryGoNext()) { 
						setStep(nextStep); 
					} 
				} 
			}); 
		} 
	} 
 
	void finishFlow() { 
		finishFlow(false); 
	} 
 
	void finishFlow(boolean forceFinish) {
		if (flow != null && step != null) {
			Wizards.saveWizardFinished(flow, step, forceFinish);
		} 
		finish(); 
	} 
 
	private boolean tryGoPrev() { 
		if (this.step == null) {
			return true; 
		} else { 
			final Fragment fragment = getSupportFragmentManager().findFragmentByTag(this.step.getFragmentTag());
			if (fragment != null) {
				return this.step.onPrev(fragment);
			} else { 
				return true; 
			} 
		} 
	} 
 
	private boolean tryGoNext() { 
		if (this.step == null) {
			return true; 
		} else { 
			final Fragment fragment = getSupportFragmentManager().findFragmentByTag(this.step.getFragmentTag());
			if (fragment != null) {
				return this.step.onNext(fragment);
			} else { 
				return true; 
			} 
		} 
	} 
 
	@Nonnull 
	private Fragment showFragment() {
		final FragmentManager fm = getSupportFragmentManager();
		final FragmentTransaction ft = fm.beginTransaction();
 
		Fragment newFragment = fm.findFragmentByTag(this.step.getFragmentTag());
 
		if (newFragment == null) {
			newFragment = Fragment.instantiate(this, this.step.getFragmentClass().getName(), this.step.getFragmentArgs());
			ft.add(R.id.wizard_content, newFragment, this.step.getFragmentTag());
		} 
 
		ft.commit();
		fm.executePendingTransactions();
 
		return newFragment;
	} 
 
	private void hideFragment() { 
		final FragmentManager fm = getSupportFragmentManager();
		final FragmentTransaction ft = fm.beginTransaction();
 
		if (this.step != null) {
			hideFragmentByTag(fm, ft, this.step.getFragmentTag());
		}