Android Open Source - AppWithTabsSample View Fragment






From Project

Back to project page AppWithTabsSample.

License

The source code is released under:

Apache License

If you think the Android project AppWithTabsSample listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package burhanloey.appwithtabssample;
/*from  w  w w.  jav  a 2 s  . c o  m*/


import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


/**
 * A simple {@link Fragment} subclass.
 *
 */
public class ViewFragment extends Fragment {

    private static final int VIEW_POST = 0;
    private static final int VIEW_COMMENT = 1;

    private int currentlyShowingFragment;

    public ViewFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_view, container, false);

        return rootView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        if (savedInstanceState == null) {
            ViewPostFragment viewPostFragment = new ViewPostFragment();
            FragmentManager fragmentManager = getChildFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.fragment_view_container, viewPostFragment);
            fragmentTransaction.commit();
            currentlyShowingFragment = VIEW_POST;
        } else {
            currentlyShowingFragment = savedInstanceState.getInt("currently_showing_fragment");
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("currently_showing_fragment", currentlyShowingFragment);
    }


}




Java Source Code List

burhanloey.appwithtabssample.ApplicationTest.java
burhanloey.appwithtabssample.HomeFragment.java
burhanloey.appwithtabssample.MainActivity.java
burhanloey.appwithtabssample.ViewCommentFragment.java
burhanloey.appwithtabssample.ViewFragment.java
burhanloey.appwithtabssample.ViewPostFragment.java
burhanloey.appwithtabssample.WriteFragment.java