質問編集履歴
1
レイアウトファイルの追記・補足の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
繰り返し表示したいです。
|
5
5
|
|
6
6
|
ただ、「←ここが上手くいかない」のところが上手くいきません。
|
7
|
+
(DailyCalendarFragment.javaの56行目)
|
7
8
|
ライフサイクルメソッドで、順序を付けているつもりなんですが、
|
8
9
|
Timely_RecyclerView_Adapterの実行 → クエリの実行
|
9
10
|
となってしまい、Timely_RecyclerView_Adapterへクエリの実行結果
|
@@ -21,29 +22,8 @@
|
|
21
22
|
```DailyCalendarFragment.java
|
22
23
|
package com.example.RecordTime;
|
23
24
|
|
24
|
-
|
25
|
+
~省略~
|
25
26
|
|
26
|
-
import androidx.annotation.NonNull;
|
27
|
-
import androidx.annotation.Nullable;
|
28
|
-
import androidx.fragment.app.Fragment;
|
29
|
-
import androidx.recyclerview.widget.LinearLayoutManager;
|
30
|
-
import androidx.recyclerview.widget.RecyclerView;
|
31
|
-
import androidx.room.Room;
|
32
|
-
|
33
|
-
import android.util.Log;
|
34
|
-
import android.view.LayoutInflater;
|
35
|
-
import android.view.View;
|
36
|
-
import android.view.ViewGroup;
|
37
|
-
|
38
|
-
import com.example.RecordTime.Room.Database;
|
39
|
-
import com.example.RecordTime.Room.TimeTable_Dao;
|
40
|
-
import com.example.RecordTime.Room.TimeTable_RoomEntity;
|
41
|
-
|
42
|
-
import java.util.List;
|
43
|
-
import java.util.concurrent.ExecutorService;
|
44
|
-
import java.util.concurrent.Executors;
|
45
|
-
import java.util.concurrent.Future;
|
46
|
-
|
47
27
|
public class DailyCalendarFragment extends Fragment {
|
48
28
|
|
49
29
|
public static List<TimeTable_RoomEntity> allTimeTable;
|
@@ -109,20 +89,8 @@
|
|
109
89
|
```Timely_RecyclerView_Adapter.java
|
110
90
|
package com.example.RecordTime;
|
111
91
|
|
112
|
-
import android.content.Context;
|
113
|
-
|
92
|
+
~省略~
|
114
|
-
import android.view.LayoutInflater;
|
115
|
-
import android.view.View;
|
116
|
-
import android.view.ViewGroup;
|
117
|
-
import android.widget.TextView;
|
118
93
|
|
119
|
-
import androidx.annotation.NonNull;
|
120
|
-
import androidx.recyclerview.widget.RecyclerView;
|
121
|
-
|
122
|
-
import com.example.RecordTime.Room.TimeTable_RoomEntity;
|
123
|
-
|
124
|
-
import java.util.List;
|
125
|
-
|
126
94
|
public class Timely_RecyclerView_Adapter extends RecyclerView.Adapter<Timely_RecyclerView_Adapter.ViewHolder> {
|
127
95
|
|
128
96
|
|
@@ -166,6 +134,143 @@
|
|
166
134
|
}
|
167
135
|
// ============= viewHolder =============
|
168
136
|
}
|
137
|
+
```
|
169
138
|
|
170
139
|
|
140
|
+
### レイアウト追記
|
141
|
+
①今回メインとして扱うレイアウト
|
142
|
+
```daily_calendar_fragment.xml
|
143
|
+
<?xml version="1.0" encoding="utf-8"?>
|
144
|
+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
145
|
+
xmlns:tools="http://schemas.android.com/tools"
|
146
|
+
android:layout_width="300dp"
|
147
|
+
android:layout_height="500dp"
|
148
|
+
android:background="@drawable/border"
|
149
|
+
tools:context=".DailyCalendarFragment">
|
150
|
+
|
151
|
+
<androidx.recyclerview.widget.RecyclerView
|
152
|
+
android:id="@+id/time_recycler_view_container"
|
153
|
+
android:layout_width="match_parent"
|
154
|
+
android:layout_height="match_parent" />
|
155
|
+
</FrameLayout>
|
171
156
|
```
|
157
|
+
|
158
|
+
②メインのフラグメント内のRecyclerViewのViewholder
|
159
|
+
```time_viewholder.xml
|
160
|
+
<?xml version="1.0" encoding="utf-8"?>
|
161
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
162
|
+
android:layout_width="match_parent"
|
163
|
+
android:layout_height="match_parent">
|
164
|
+
|
165
|
+
<TextView
|
166
|
+
android:id="@+id/time_view_holder"
|
167
|
+
android:layout_width="match_parent"
|
168
|
+
android:layout_height="wrap_content"
|
169
|
+
android:layout_weight="1"
|
170
|
+
android:ems="10"
|
171
|
+
android:text="@string/time_view_holder" />
|
172
|
+
</LinearLayout>
|
173
|
+
```
|
174
|
+
※③今回のメインフラグメントを置くフラグメント
|
175
|
+
```date_fragment.xml
|
176
|
+
<?xml version="1.0" encoding="utf-8"?>
|
177
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
178
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
179
|
+
xmlns:tools="http://schemas.android.com/tools"
|
180
|
+
android:layout_width="match_parent"
|
181
|
+
android:layout_height="match_parent">
|
182
|
+
|
183
|
+
<LinearLayout
|
184
|
+
android:id="@+id/date"
|
185
|
+
android:layout_width="match_parent"
|
186
|
+
android:layout_height="25sp"
|
187
|
+
android:layout_marginBottom="706dp"
|
188
|
+
android:backgroundTint="@color/design_default_color_primary_dark"
|
189
|
+
android:gravity="center"
|
190
|
+
android:orientation="horizontal"
|
191
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
192
|
+
app:layout_constraintEnd_toEndOf="parent"
|
193
|
+
app:layout_constraintStart_toStartOf="parent"
|
194
|
+
app:layout_constraintTop_toTopOf="parent">
|
195
|
+
|
196
|
+
<TextView
|
197
|
+
android:id="@+id/selected_month"
|
198
|
+
android:layout_width="wrap_content"
|
199
|
+
android:layout_height="wrap_content"
|
200
|
+
android:text="@string/fuu" />
|
201
|
+
|
202
|
+
<TextView
|
203
|
+
android:id="@+id/selected_date"
|
204
|
+
android:layout_width="wrap_content"
|
205
|
+
android:layout_height="wrap_content"
|
206
|
+
android:text="@string/selected_date" />
|
207
|
+
</LinearLayout>
|
208
|
+
|
209
|
+
<androidx.fragment.app.FragmentContainerView
|
210
|
+
android:id="@+id/fragmentContainerView"
|
211
|
+
android:name="com.example.RecordTime.DailyCalendarFragment"
|
212
|
+
android:layout_width="wrap_content"
|
213
|
+
android:layout_height="wrap_content"
|
214
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
215
|
+
app:layout_constraintEnd_toEndOf="parent"
|
216
|
+
app:layout_constraintStart_toStartOf="parent"
|
217
|
+
app:layout_constraintTop_toBottomOf="@+id/date" />
|
218
|
+
|
219
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
220
|
+
```
|
221
|
+
|
222
|
+
|
223
|
+
★★★引数自体は渡せたかと思いましたがエラーが出るパターン★★★
|
224
|
+
エラー:No adapter attached; skipping layout
|
225
|
+
|
226
|
+
```DailyCalendarFragment.java
|
227
|
+
package com.example.RecordTime;
|
228
|
+
~省略~
|
229
|
+
|
230
|
+
public class DailyCalendarFragment extends Fragment {
|
231
|
+
|
232
|
+
@Override
|
233
|
+
public void onCreate(Bundle savedInstanceState) {
|
234
|
+
super.onCreate(savedInstanceState);
|
235
|
+
}
|
236
|
+
|
237
|
+
@Override
|
238
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
239
|
+
Bundle savedInstanceState) {
|
240
|
+
View view = inflater.inflate(R.layout.daily_calendar_fragment, container, false);
|
241
|
+
loadDB(view);
|
242
|
+
return view;
|
243
|
+
}
|
244
|
+
|
245
|
+
public void loadDB(View view) {
|
246
|
+
ExecutorService executor = Executors.newSingleThreadExecutor();
|
247
|
+
|
248
|
+
executor.submit(new Runnable() {
|
249
|
+
@Override
|
250
|
+
public void run() {
|
251
|
+
Database database = Room.databaseBuilder(getContext(), Database.class, "TimeTable").build();
|
252
|
+
|
253
|
+
TimeTable_Dao dao = database.timeTable_dao();
|
254
|
+
dao.insert(new TimeTable_RoomEntity("0番目のtitle"));
|
255
|
+
dao.insert(new TimeTable_RoomEntity("1番目のtitle"));
|
256
|
+
dao.insert(new TimeTable_RoomEntity("2番目のtitle"));
|
257
|
+
|
258
|
+
List<TimeTable_RoomEntity> allTimeTable = dao.getAll();
|
259
|
+
|
260
|
+
setRecyclerView(view, allTimeTable);
|
261
|
+
}
|
262
|
+
});
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
public void setRecyclerView(View view, List<TimeTable_RoomEntity> allTimeTable) {
|
267
|
+
// RecyclerView を生成して各時間を生成
|
268
|
+
RecyclerView recyclerView = view.findViewById(R.id.time_recycler_view_container);
|
269
|
+
// ①recycleView に layoutManager をセット
|
270
|
+
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
271
|
+
// ②Adapter を生成して RecyclerView にセット
|
272
|
+
recyclerView.setAdapter(new Timely_RecyclerView_Adapter(getContext(), allTimeTable));
|
273
|
+
}
|
274
|
+
}
|
275
|
+
```
|
276
|
+
|