Tesis 1.0.0
Loading...
Searching...
No Matches
SelectedProductFragment.java
Go to the documentation of this file.
1package com.example.food_front;
2
3import android.os.Bundle;
4import android.view.LayoutInflater;
5import android.view.View;
6import android.view.ViewGroup;
7import android.widget.Button;
8
9import androidx.fragment.app.Fragment;
10import androidx.fragment.app.FragmentManager;
11import androidx.fragment.app.FragmentTransaction;
12
18public class SelectedProductFragment extends Fragment {
19
21 // Required empty public constructor
22 }
23
24 @Override
25 public View onCreateView(LayoutInflater inflater, ViewGroup container,
26 Bundle savedInstanceState) {
27 // Inflate the layout for this fragment
28 View view = inflater.inflate(R.layout.fragment_selected_product, container, false);
29
30 Button button = view.findViewById(R.id.addButton);
31
32 button.setOnClickListener(new View.OnClickListener() {
33 @Override
34 public void onClick(View v) {
35 replaceFragment(new CartFragment()); // Replace with another fragment
36 }
37 });
38
39 return view;
40 }
41
42 private void replaceFragment(Fragment newFragment) {
43 // Get the FragmentManager and start a transaction
44
45 FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
46 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
47 fragmentTransaction.replace(R.id.fragment_container_view, newFragment);
48 fragmentTransaction.addToBackStack(null);
49 fragmentTransaction.commit();
50 }
51}
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)