質問編集履歴
1
関連ファイルを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -260,6 +260,8 @@
|
|
260
260
|
|
261
261
|
`場所: タイプTableLayoutの変数 calendarTableLayout`
|
262
262
|
|
263
|
+
|
264
|
+
|
263
265
|
```ここに言語を入力
|
264
266
|
|
265
267
|
import android.os.Bundle;
|
@@ -366,7 +368,7 @@
|
|
366
368
|
|
367
369
|
mCalendarAdapter = new CalendarAdapter(getActivity());
|
368
370
|
|
369
|
-
calendarTableLayout.setAdapter(mCalendarAdapter);
|
371
|
+
calendarTableLayout.setAdapter(mCalendarAdapter); //エラー箇所
|
370
372
|
|
371
373
|
monthText.setText(mCalendarAdapter.getTitle());
|
372
374
|
|
@@ -381,3 +383,163 @@
|
|
381
383
|
}
|
382
384
|
|
383
385
|
```
|
386
|
+
|
387
|
+
---
|
388
|
+
|
389
|
+
関連ファイル
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
・DateManager.java
|
394
|
+
|
395
|
+
```ここに言語を入力
|
396
|
+
|
397
|
+
import java.text.SimpleDateFormat;
|
398
|
+
|
399
|
+
import java.util.ArrayList;
|
400
|
+
|
401
|
+
import java.util.Calendar;
|
402
|
+
|
403
|
+
import java.util.Date;
|
404
|
+
|
405
|
+
import java.util.List;
|
406
|
+
|
407
|
+
import java.util.Locale;
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
public class DateManager{
|
412
|
+
|
413
|
+
Calendar mCalendar;
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
public DateManager(){
|
418
|
+
|
419
|
+
mCalendar = Calendar.getInstance();
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
//当月の要素を取得
|
426
|
+
|
427
|
+
public List<Date> getDays(){
|
428
|
+
|
429
|
+
//現在の状態を保持
|
430
|
+
|
431
|
+
Date startDate = mCalendar.getTime();
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
//GridViewに表示するマスの合計を計算
|
436
|
+
|
437
|
+
int count = getWeeks() * 7 ;
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
//当月のカレンダーに表示される前月分の日数を計算
|
442
|
+
|
443
|
+
mCalendar.set(Calendar.DATE, 1);
|
444
|
+
|
445
|
+
int dayOfWeek = mCalendar.get(Calendar.DAY_OF_WEEK) - 1;
|
446
|
+
|
447
|
+
mCalendar.add(Calendar.DATE, -dayOfWeek);
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
List<Date> days = new ArrayList<>();
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
for (int i = 0; i < count; i ++){
|
456
|
+
|
457
|
+
days.add(mCalendar.getTime());
|
458
|
+
|
459
|
+
mCalendar.add(Calendar.DATE, 1);
|
460
|
+
|
461
|
+
}
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
//状態を復元
|
466
|
+
|
467
|
+
mCalendar.setTime(startDate);
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
return days;
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
//当月かどうか確認
|
478
|
+
|
479
|
+
public boolean isCurrentMonth(Date date){
|
480
|
+
|
481
|
+
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM", Locale.US);
|
482
|
+
|
483
|
+
String currentMonth = format.format(mCalendar.getTime());
|
484
|
+
|
485
|
+
if (currentMonth.equals(format.format(date))){
|
486
|
+
|
487
|
+
return true;
|
488
|
+
|
489
|
+
}else {
|
490
|
+
|
491
|
+
return false;
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
//週数を取得
|
500
|
+
|
501
|
+
public int getWeeks(){
|
502
|
+
|
503
|
+
return mCalendar.getActualMaximum(Calendar.WEEK_OF_MONTH);
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
//曜日を取得
|
510
|
+
|
511
|
+
public int getDayOfWeek(Date date) {
|
512
|
+
|
513
|
+
Calendar calendar = Calendar.getInstance();
|
514
|
+
|
515
|
+
calendar.setTime(date);
|
516
|
+
|
517
|
+
return calendar.get(Calendar.DAY_OF_WEEK);
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
//翌月へ
|
524
|
+
|
525
|
+
public void nextMonth(){
|
526
|
+
|
527
|
+
mCalendar.add(Calendar.MONTH, 1);
|
528
|
+
|
529
|
+
}
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
//前月へ
|
534
|
+
|
535
|
+
public void prevMonth(){
|
536
|
+
|
537
|
+
mCalendar.add(Calendar.MONTH, -1);
|
538
|
+
|
539
|
+
}
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
}
|
544
|
+
|
545
|
+
```
|