teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コード追加

2016/05/22 12:30

投稿

akamakku
akamakku

スコア191

title CHANGED
File without changes
body CHANGED
@@ -8,4 +8,136 @@
8
8
 
9
9
  Buttonには、それぞれcolumnを設定しています。
10
10
 
11
- なにか設定が必要なのでしょうか?
11
+ なにか設定が必要なのでしょうか?
12
+
13
+ ```Java
14
+
15
+
16
+ import android.os.Bundle;
17
+ import android.support.annotation.IntegerRes;
18
+ import android.support.v4.app.Fragment;
19
+ import android.view.LayoutInflater;
20
+ import android.view.View;
21
+ import android.view.ViewGroup;
22
+ import android.widget.Button;
23
+ import android.widget.TableLayout;
24
+ import android.widget.TableRow;
25
+ import android.widget.TextView;
26
+
27
+ import java.util.Calendar;
28
+
29
+
30
+ /**
31
+ * A simple {@link Fragment} subclass.
32
+ */
33
+ public class FragmentChooseDay extends Fragment implements View.OnClickListener{
34
+
35
+ private int tableRowId[] = {R.id.row0, R.id.row1, R.id.row2, R.id.row3, R.id.row4, R.id.row5};
36
+ private Button button[];
37
+ private TextView textView;
38
+ private Calendar calendar;
39
+ private TableRow tableRow;
40
+
41
+ public FragmentChooseDay() {
42
+ // Required empty public constructor
43
+ }
44
+
45
+
46
+ @Override
47
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
48
+ Bundle savedInstanceState) {
49
+ // Inflate the layout for this fragment
50
+ View view = inflater.inflate(R.layout.fragment_choose_day, container, false);
51
+
52
+ Bundle bundle = getArguments();
53
+ int month = bundle.getInt("month");
54
+ int year = bundle.getInt("year");
55
+ textView = (TextView)view.findViewById(R.id.textView);
56
+ textView.setText(year + "年" + (month+1) + "月");
57
+
58
+ calendar = Calendar.getInstance();
59
+ calendar.clear();
60
+ calendar.set(year, month, 1);
61
+
62
+ int num_day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
63
+
64
+ button = new Button[num_day];
65
+
66
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
67
+ int num_Row = 1;
68
+ int d = 1;
69
+
70
+ for(int i = 0; i < num_day; i++){
71
+ button[i] = new Button(getActivity());
72
+ button[i].setText(Integer.toString(d++));
73
+ button[i].setOnClickListener(this);
74
+ tableRow = (TableRow)view.findViewById(tableRowId[num_Row]);
75
+ tableRow.addView(button[i],new TableRow.LayoutParams(dayOfWeek++-1));
76
+ if(dayOfWeek > 7){
77
+ dayOfWeek = 1;
78
+ num_Row++;
79
+ }
80
+ }
81
+
82
+
83
+
84
+
85
+
86
+
87
+ return view;
88
+ }
89
+
90
+ @Override
91
+ public void onClick(View v) {
92
+
93
+ }
94
+ }
95
+
96
+ ```
97
+
98
+ ```xml
99
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
100
+ xmlns:tools="http://schemas.android.com/tools"
101
+ android:layout_width="match_parent"
102
+ android:layout_height="match_parent"
103
+ android:orientation="vertical"
104
+ tools:context="×××.reminder.FragmentChooseDay">
105
+
106
+ <!-- TODO: Update blank fragment layout -->
107
+ <TextView
108
+ android:layout_width="wrap_content"
109
+ android:layout_height="wrap_content"
110
+ android:textSize="12pt"
111
+ android:id="@+id/textView"/>
112
+ <TableLayout
113
+ android:layout_width="match_parent"
114
+ android:layout_height="match_parent">
115
+ <TableRow
116
+ android:layout_width="match_parent"
117
+ android:layout_weight="1"
118
+ android:id="@+id/row0"></TableRow>
119
+ <TableRow
120
+ android:layout_width="match_parent"
121
+ android:layout_weight="2"
122
+ android:id="@+id/row1"></TableRow>
123
+ <TableRow
124
+ android:layout_width="match_parent"
125
+ android:layout_weight="2"
126
+ android:id="@+id/row2"></TableRow>
127
+ <TableRow
128
+ android:layout_width="match_parent"
129
+ android:layout_weight="2"
130
+ android:id="@+id/row3"></TableRow>
131
+ <TableRow
132
+ android:layout_width="match_parent"
133
+ android:layout_weight="2"
134
+ android:id="@+id/row4"></TableRow>
135
+ <TableRow
136
+ android:layout_width="match_parent"
137
+ android:layout_weight="2"
138
+ android:id="@+id/row5"></TableRow>
139
+
140
+ </TableLayout>
141
+
142
+ </LinearLayout>
143
+ ```