質問編集履歴

2

文法の修正

2019/01/06 07:23

投稿

Aies
Aies

スコア21

test CHANGED
File without changes
test CHANGED
@@ -388,7 +388,7 @@
388
388
 
389
389
  public String getTitle(){
390
390
 
391
- SimpleDateFormat format = new SimpleDateFormat("yyyy.MM", Locale.US);
391
+ SimpleDateFormat format = new SimpleDateFormat("yyyy.MM", Locale.JAPAN);
392
392
 
393
393
  return format.format(mDateManager.mCalendar.getTime());
394
394
 
@@ -444,4 +444,8 @@
444
444
 
445
445
 
446
446
 
447
+ readDataの呼び出し部分は上から三番目のソース内の「//その月日の金額をまとめる」というコメントがついてる部分です。
448
+
449
+
450
+
447
451
  調べてもいまいちわからなかったのでよろしければご助言お願いいたします。

1

データソースの追記

2019/01/06 07:23

投稿

Aies
Aies

スコア21

test CHANGED
File without changes
test CHANGED
@@ -206,6 +206,228 @@
206
206
 
207
207
  ```
208
208
 
209
+ ```AndroidStudio
210
+
211
+ public class CalendarAdapter extends BaseAdapter {
212
+
213
+ private List<Date> dateArray = new ArrayList();
214
+
215
+ private Context mContext;
216
+
217
+ private DateManager mDateManager;
218
+
219
+ private LayoutInflater mLayoutInflater;
220
+
221
+ private String price;
222
+
223
+ private SQLiteDatabase db;
224
+
225
+ private KakeiboDatabase kDB;
226
+
227
+
228
+
229
+ //カスタムセルを拡張したらここでWigetを定義
230
+
231
+ private static class ViewHolder {
232
+
233
+ public TextView dateText;
234
+
235
+ }
236
+
237
+
238
+
239
+ public CalendarAdapter(Context context){
240
+
241
+ mContext = context;
242
+
243
+ mLayoutInflater = LayoutInflater.from(mContext);
244
+
245
+ mDateManager = new DateManager();
246
+
247
+ dateArray = mDateManager.getDays();
248
+
249
+ }
250
+
251
+
252
+
253
+ @Override
254
+
255
+ public int getCount() {
256
+
257
+ return dateArray.size();
258
+
259
+ }
260
+
261
+
262
+
263
+ @Override
264
+
265
+ public View getView(int position, View convertView, ViewGroup parent) {
266
+
267
+ ViewHolder holder;
268
+
269
+ if (convertView == null) {
270
+
271
+ convertView = mLayoutInflater.inflate(R.layout.calendar_cell, null);
272
+
273
+ holder = new ViewHolder();
274
+
275
+ holder.dateText = convertView.findViewById(R.id.dateText);
276
+
277
+ convertView.setTag(holder);
278
+
279
+ } else {
280
+
281
+ holder = (ViewHolder)convertView.getTag();
282
+
283
+ }
284
+
285
+
286
+
287
+ //セルのサイズを指定
288
+
289
+ float dp = mContext.getResources().getDisplayMetrics().density;
290
+
291
+ AbsListView.LayoutParams params = new AbsListView.LayoutParams(parent.getWidth()/7 - (int)dp, (parent.getHeight() - (int)dp * mDateManager.getWeeks() ) / mDateManager.getWeeks());
292
+
293
+ convertView.setLayoutParams(params);
294
+
295
+
296
+
297
+ //その月日の金額をまとめる
298
+
299
+ SimpleDateFormat dateF = new SimpleDateFormat("yyyy-MM-dd", Locale.JAPAN);
300
+
301
+ MainActivity main = new MainActivity();
302
+
303
+ price = main.readData(dateF.format(dateArray.get(position)));
304
+
305
+
306
+
307
+ //日付とデータベースの金額を表示させる
308
+
309
+ SimpleDateFormat dateFormat = new SimpleDateFormat("d", Locale.JAPAN);
310
+
311
+ holder.dateText.setText(dateFormat.format(dateArray.get(position)) + "\n" + price);
312
+
313
+
314
+
315
+ //当月以外のセルをグレーアウト
316
+
317
+ if (mDateManager.isCurrentMonth(dateArray.get(position))){
318
+
319
+ convertView.setBackgroundColor(Color.WHITE);
320
+
321
+ }else {
322
+
323
+ convertView.setBackgroundColor(Color.LTGRAY);
324
+
325
+ }
326
+
327
+
328
+
329
+ //日曜日を赤、土曜日を青に
330
+
331
+ int colorId;
332
+
333
+ switch (mDateManager.getDayOfWeek(dateArray.get(position))){
334
+
335
+ case 1:
336
+
337
+ colorId = Color.RED;
338
+
339
+ break;
340
+
341
+ case 7:
342
+
343
+ colorId = Color.BLUE;
344
+
345
+ break;
346
+
347
+
348
+
349
+ default:
350
+
351
+ colorId = Color.BLACK;
352
+
353
+ break;
354
+
355
+ }
356
+
357
+ holder.dateText.setTextColor(colorId);
358
+
359
+
360
+
361
+ return convertView;
362
+
363
+ }
364
+
365
+
366
+
367
+ @Override
368
+
369
+ public long getItemId(int position) {
370
+
371
+ return 0;
372
+
373
+ }
374
+
375
+
376
+
377
+ @Override
378
+
379
+ public Object getItem(int position) {
380
+
381
+ return null;
382
+
383
+ }
384
+
385
+
386
+
387
+ //表示月を取得
388
+
389
+ public String getTitle(){
390
+
391
+ SimpleDateFormat format = new SimpleDateFormat("yyyy.MM", Locale.US);
392
+
393
+ return format.format(mDateManager.mCalendar.getTime());
394
+
395
+ }
396
+
397
+
398
+
399
+ //翌月表示
400
+
401
+ public void nextMonth(){
402
+
403
+ mDateManager.nextMonth();
404
+
405
+ dateArray = mDateManager.getDays();
406
+
407
+ this.notifyDataSetChanged();
408
+
409
+ }
410
+
411
+
412
+
413
+ //前月表示
414
+
415
+ public void prevMonth(){
416
+
417
+ mDateManager.prevMonth();
418
+
419
+ dateArray = mDateManager.getDays();
420
+
421
+ this.notifyDataSetChanged();
422
+
423
+ }
424
+
425
+ }
426
+
427
+
428
+
429
+ ```
430
+
209
431
 
210
432
 
211
433
  このMainActivityにあるreadDataを外部から呼び出したときに