materialtest.vivz.slidenerd.fragments.EnregistrementEtat.java Source code

Java tutorial

Introduction

Here is the source code for materialtest.vivz.slidenerd.fragments.EnregistrementEtat.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package materialtest.vivz.slidenerd.fragments;

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

import materialtest.vivz.slidenerd.materialtest.R;

/**
 * @author AYMEN
 */
public class EnregistrementEtat extends Fragment {
    FrameLayout lay1;
    Button declancher, annuler;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        FragmentActivity EnregistrementEtat = (FragmentActivity) super.getActivity();
        // Replace LinearLayout by the type of the root element of the layout you're trying to load
        FrameLayout llLayout = (FrameLayout) inflater.inflate(R.layout.etat, container, false);
        // Of course you will want to faActivity and llLayout in the class and not this method to access them in the rest of
        // the class, just initialize them here

        // Content of previous onCreate() here
        // ...
        lay1 = (FrameLayout) llLayout.findViewById(R.id.lay1);
        // Don't use this method, it's handled by inflater.inflate() above :
        // setContentView(R.layout.activity_layout);
        declancher = (Button) llLayout.findViewById(R.id.declancher);
        declancher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment fragment = new TestPoulse();
                FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.lay1, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                fragmentTransaction.commit();
            }
        });
        annuler = (Button) llLayout.findViewById(R.id.annuler);
        annuler.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment fragment = new FragmentBoxOffice();
                FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.lay1, fragment);

                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                fragmentTransaction.commit();
            }
        });
        return llLayout; // We must return the loaded Layout
    }
}