problem when going from one fragmet to another [closed]

0

Hello, the problem is that I'm trying to go from Fragment to another

by a button but when I touch the button the other Fragment is positioned on top of the first one, that is, the two fragment are displayed on the screen at the same time and you would only have to visualize one.

What I'm looking for in the end is to load a view with another Toolbar.

This is the code I'm using to move to the other Fragment

public class Fragmen2 extends Fragment {

Button Tboton,
        Lboton,
        Pboton,
        Dboton;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_fragmen2, container, false);


    Tboton = (Button)view.findViewById(R.id.boton1fragmen2); /**boton que conecta el fragment 2 con la actividad temperatura */
    Tboton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            Intent Tboton = new Intent( getActivity() ,Temperatura.class);
            startActivity(Tboton);
        }
    });


   //Lboton =(Button)view.findViewById(R.id.boton2fragmen2); /**boton que conecta el fragment 2 con la actividad distancias */


 //  Lboton.setOnClickListener(new View.OnClickListener() {
       // @Override
    //    public void onClick(View v) {

          //  Intent Lboton = new Intent(getActivity() , DimensionFragment.class);
          //  startActivity(Lboton);

       // }
   // });

    View v = inflater.inflate(R.layout.fragment_fragmen1, container, false);

    Pboton = (Button)view.findViewById(R.id.boton3fragmen2);    /**boton que conecta el fragment 2 con la actividad power */
    Pboton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DimensionFragment dimensionFragment = new DimensionFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction =        fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.fragmen2, dimensionFragment);
            //fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }


    });


    Dboton = (Button)view.findViewById(R.id.boton4fragmen2);
    Dboton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent Dboton = new Intent(getActivity(),Dimensions.class);
            startActivity(Dboton);
        }
    });

    return  view;

}




}

This is how the view looks like

    
asked by Liantony Pozo 28.04.2017 в 02:18
source

1 answer

1

Are you sure you're calling the FragmentManager correctly? Use:

FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    
answered by 28.04.2017 в 07:42