質問編集履歴

1

コード追加

2016/05/22 12:30

投稿

akamakku
akamakku

スコア191

test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,267 @@
19
19
 
20
20
 
21
21
  なにか設定が必要なのでしょうか?
22
+
23
+
24
+
25
+ ```Java
26
+
27
+
28
+
29
+
30
+
31
+ import android.os.Bundle;
32
+
33
+ import android.support.annotation.IntegerRes;
34
+
35
+ import android.support.v4.app.Fragment;
36
+
37
+ import android.view.LayoutInflater;
38
+
39
+ import android.view.View;
40
+
41
+ import android.view.ViewGroup;
42
+
43
+ import android.widget.Button;
44
+
45
+ import android.widget.TableLayout;
46
+
47
+ import android.widget.TableRow;
48
+
49
+ import android.widget.TextView;
50
+
51
+
52
+
53
+ import java.util.Calendar;
54
+
55
+
56
+
57
+
58
+
59
+ /**
60
+
61
+ * A simple {@link Fragment} subclass.
62
+
63
+ */
64
+
65
+ public class FragmentChooseDay extends Fragment implements View.OnClickListener{
66
+
67
+
68
+
69
+ private int tableRowId[] = {R.id.row0, R.id.row1, R.id.row2, R.id.row3, R.id.row4, R.id.row5};
70
+
71
+ private Button button[];
72
+
73
+ private TextView textView;
74
+
75
+ private Calendar calendar;
76
+
77
+ private TableRow tableRow;
78
+
79
+
80
+
81
+ public FragmentChooseDay() {
82
+
83
+ // Required empty public constructor
84
+
85
+ }
86
+
87
+
88
+
89
+
90
+
91
+ @Override
92
+
93
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
94
+
95
+ Bundle savedInstanceState) {
96
+
97
+ // Inflate the layout for this fragment
98
+
99
+ View view = inflater.inflate(R.layout.fragment_choose_day, container, false);
100
+
101
+
102
+
103
+ Bundle bundle = getArguments();
104
+
105
+ int month = bundle.getInt("month");
106
+
107
+ int year = bundle.getInt("year");
108
+
109
+ textView = (TextView)view.findViewById(R.id.textView);
110
+
111
+ textView.setText(year + "年" + (month+1) + "月");
112
+
113
+
114
+
115
+ calendar = Calendar.getInstance();
116
+
117
+ calendar.clear();
118
+
119
+ calendar.set(year, month, 1);
120
+
121
+
122
+
123
+ int num_day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
124
+
125
+
126
+
127
+ button = new Button[num_day];
128
+
129
+
130
+
131
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
132
+
133
+ int num_Row = 1;
134
+
135
+ int d = 1;
136
+
137
+
138
+
139
+ for(int i = 0; i < num_day; i++){
140
+
141
+ button[i] = new Button(getActivity());
142
+
143
+ button[i].setText(Integer.toString(d++));
144
+
145
+ button[i].setOnClickListener(this);
146
+
147
+ tableRow = (TableRow)view.findViewById(tableRowId[num_Row]);
148
+
149
+ tableRow.addView(button[i],new TableRow.LayoutParams(dayOfWeek++-1));
150
+
151
+ if(dayOfWeek > 7){
152
+
153
+ dayOfWeek = 1;
154
+
155
+ num_Row++;
156
+
157
+ }
158
+
159
+ }
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+ return view;
174
+
175
+ }
176
+
177
+
178
+
179
+ @Override
180
+
181
+ public void onClick(View v) {
182
+
183
+
184
+
185
+ }
186
+
187
+ }
188
+
189
+
190
+
191
+ ```
192
+
193
+
194
+
195
+ ```xml
196
+
197
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
198
+
199
+ xmlns:tools="http://schemas.android.com/tools"
200
+
201
+ android:layout_width="match_parent"
202
+
203
+ android:layout_height="match_parent"
204
+
205
+ android:orientation="vertical"
206
+
207
+ tools:context="×××.reminder.FragmentChooseDay">
208
+
209
+
210
+
211
+ <!-- TODO: Update blank fragment layout -->
212
+
213
+ <TextView
214
+
215
+ android:layout_width="wrap_content"
216
+
217
+ android:layout_height="wrap_content"
218
+
219
+ android:textSize="12pt"
220
+
221
+ android:id="@+id/textView"/>
222
+
223
+ <TableLayout
224
+
225
+ android:layout_width="match_parent"
226
+
227
+ android:layout_height="match_parent">
228
+
229
+ <TableRow
230
+
231
+ android:layout_width="match_parent"
232
+
233
+ android:layout_weight="1"
234
+
235
+ android:id="@+id/row0"></TableRow>
236
+
237
+ <TableRow
238
+
239
+ android:layout_width="match_parent"
240
+
241
+ android:layout_weight="2"
242
+
243
+ android:id="@+id/row1"></TableRow>
244
+
245
+ <TableRow
246
+
247
+ android:layout_width="match_parent"
248
+
249
+ android:layout_weight="2"
250
+
251
+ android:id="@+id/row2"></TableRow>
252
+
253
+ <TableRow
254
+
255
+ android:layout_width="match_parent"
256
+
257
+ android:layout_weight="2"
258
+
259
+ android:id="@+id/row3"></TableRow>
260
+
261
+ <TableRow
262
+
263
+ android:layout_width="match_parent"
264
+
265
+ android:layout_weight="2"
266
+
267
+ android:id="@+id/row4"></TableRow>
268
+
269
+ <TableRow
270
+
271
+ android:layout_width="match_parent"
272
+
273
+ android:layout_weight="2"
274
+
275
+ android:id="@+id/row5"></TableRow>
276
+
277
+
278
+
279
+ </TableLayout>
280
+
281
+
282
+
283
+ </LinearLayout>
284
+
285
+ ```