-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFragment.java
133 lines (94 loc) · 5.1 KB
/
MainFragment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.example.padel;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import java.lang.reflect.Field;
public class MainFragment extends Fragment {
FragmentManager fragmentManager;
public MainFragment() {
// Required empty public constructor
}
public static MainFragment newInstance(String param1, String param2) {
MainFragment fragment = new MainFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentManager = getParentFragmentManager();
}
//mi prendo il bottone e gli setto l'onClick e mi manderà ad un fragment per la prenotazione
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_main, container, false);
ImageButton buttonField1 = (ImageButton) view.findViewById(R.id.field_one);
buttonField1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Field1Fragment fragment = new Field1Fragment();
Bundle data = new Bundle();
String field1 = "field1";
data.putString("field",field1);
fragment.setArguments(data);
fragmentManager.beginTransaction().replace(R.id.fragmentContainerView, fragment, null) //vogliamo indicare di spaostarci da questo fragment ad un altro, cambia quello che è in questo containetr con un nuovo fragment
.setReorderingAllowed(true) //reordering allowed
.addToBackStack("name") // così che se faccio indietro ritorna a questo fragment
.commit();
}
});
ImageButton buttonField2 = (ImageButton) view.findViewById(R.id.field_two);
buttonField2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Field1Fragment fragment = new Field1Fragment();
Bundle data = new Bundle();
data.putString("field","field2");
fragment.setArguments(data);
fragmentManager.beginTransaction() //indico di iniziare una transazione da un fragment ad un altro
.replace(R.id.fragmentContainerView, fragment, null) //vogliamo indicare di spaostarci da questo fragment ad un altro, cambia quello che è in questo containetr con un nuovo fragment
.setReorderingAllowed(true) //reordering allowed
.addToBackStack("name") // così che se faccio indietro ritorna a questo fragment
.commit();
}
});
ImageButton buttonField3 = (ImageButton) view.findViewById(R.id.field_three);
buttonField3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Field1Fragment fragment = new Field1Fragment();
Bundle data = new Bundle();
data.putString("field","field3");
System.out.println(data);
fragment.setArguments(data);
fragmentManager.beginTransaction() //indico di iniziare una transazione da un fragment ad un altro
.replace(R.id.fragmentContainerView, fragment, null) //vogliamo indicare di spaostarci da questo fragment ad un altro, cambia quello che è in questo containetr con un nuovo fragment
.setReorderingAllowed(true) //reordering allowed
.addToBackStack("name") // così che se faccio indietro ritorna a questo fragment
.commit();
}
});
ImageButton buttonField4 = (ImageButton) view.findViewById(R.id.field_four);
buttonField4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Field1Fragment fragment = new Field1Fragment();
Bundle data = new Bundle();
data.putString("field","field4");
fragment.setArguments(data);
fragmentManager.beginTransaction() //indico di iniziare una transazione da un fragment ad un altro
.replace(R.id.fragmentContainerView, fragment, null) //vogliamo indicare di spaostarci da questo fragment ad un altro, cambia quello che è in questo containetr con un nuovo fragment
.setReorderingAllowed(true) //reordering allowed
.addToBackStack("name") // così che se faccio indietro ritorna a questo fragment
.commit();
}
});
return view;
}
}