MyTetra Share
Делитесь знаниями!
SingleFragmentActivity.java
20.04.2017
15:51
Раздел: Android - books - AndroidProgramming2e - 9 Вывод списков и ListFragment
SingleFragmentActivity.java


package com.bignerdranch.android.criminalintent; 
 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
 
public abstract class SingleFragmentActivity extends FragmentActivity { 
 
    protected abstract Fragment createFragment(); 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_fragment); 
 
        FragmentManager fm = getSupportFragmentManager(); 
        Fragment fragment = fm.findFragmentById(R.id.fragment_container); 
 
        if (fragment == null) { 
            fragment = createFragment(); 
            fm.beginTransaction() 
                    .add(R.id.fragment_container, fragment) 
                    .commit(); 
        } 
    } 
 
} 

 
MyTetra Share v.0.52
Яндекс индекс цитирования