質問編集履歴

2

文字列返還箇所を追加しました

2018/01/21 11:48

投稿

.Won
.Won

スコア66

test CHANGED
File without changes
test CHANGED
@@ -10,70 +10,80 @@
10
10
 
11
11
  ```Java
12
12
 
13
+ // 日付取得箇所
14
+
13
15
  final String[] EVENT_PROJECTION = new String[]{
14
16
 
15
- Events.CALENDAR_ID,
17
+ Events.CALENDAR_ID,
16
18
 
17
- Events.ORGANIZER,
19
+ Events.ORGANIZER,
18
20
 
19
- Events.ACCOUNT_NAME,
21
+ Events.ACCOUNT_NAME,
20
22
 
21
- Events.TITLE,
23
+ Events.TITLE,
22
24
 
23
- Events.DESCRIPTION,
25
+ Events.DESCRIPTION,
24
26
 
25
- Events.DTSTART,
27
+ Events.DTSTART,
26
28
 
27
- Events.DTEND
29
+ Events.DTEND
28
30
 
29
- };
31
+ };
32
+
33
+ ContentResolver cr = getContentResolver();
34
+
35
+ String selection = "(" + Events.ACCOUNT_TYPE + " = ?)";
36
+
37
+ String[] selectionArgs = new String[]{"com.google"};
38
+
39
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != ckageManager.PERMISSION_GRANTED) {
40
+
41
+ return;
42
+
43
+ }
44
+
45
+ Cursor cur = cr.query(Events.CONTENT_URI, EVENT_PROJECTION, null, null, null);
46
+
47
+ adapter.getItemList().clear();
48
+
49
+ while(cur.moveToNext()){
50
+
51
+ Toast.makeText(MainActivity.this,cur.getString(cur.getColumnIndex(Events.DTSTART)),Tot.LENGTH_SHORT).show();
52
+
53
+ Item item = new Item();
54
+
55
+ item.dtStartLong = cur.getLong(cur.getColumnIndex(Events.DTSTART));
56
+
57
+ em.setAccountName(cur.getString(cur.getColumnIndex(Events.ACCOUNT_NAME)));
58
+
59
+ item.setId(cur.getString(cur.getColumnIndex(Events.CALENDAR_ID)));
60
+
61
+ item.setTitle(cur.getString(cur.getColumnIndex(Events.TITLE)));
62
+
63
+ item.setDetails(cur.getString(cur.getColumnIndex(Events.DESCRIPTION)));
64
+
65
+ item.setOrganizate(cur.getString(cur.getColumnIndex(Events.ORGANIZER)));
66
+
67
+ item.setDtStart(new Date(cur.getLong(cur.getColumnIndex(Events.DTSTART))));
68
+
69
+ item.setDtEnd(new Date(cur.getLong(cur.getColumnIndex(Events.DTSTART))));
70
+
71
+ adapter.getItemList().add(item);
72
+
73
+ }
30
74
 
31
75
 
32
76
 
33
- ContentResolver cr = getContentResolver();
34
-
35
- String selection = "(" + Events.ACCOUNT_TYPE + " = ?)";
36
-
37
- String[] selectionArgs = new String[]{"com.google"};
38
-
39
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
40
-
41
- return;
42
-
43
- }
44
-
45
- Cursor cur = cr.query(Events.CONTENT_URI, EVENT_PROJECTION, null, null, null);
46
77
 
47
78
 
48
79
 
49
- adapter.getItemList().clear();
50
80
 
51
- while(cur.moveToNext()){
81
+ // 文字列変換箇所
52
82
 
53
- Toast.makeText(MainActivity.this,cur.getString(cur.getColumnIndex(Events.DTSTART)),Toast.LENGTH_SHORT).show();
83
+ public String getDtStartToString(){
54
84
 
55
- Item item = new Item();
85
+ return String.valueOf(dtStart.getYear() + "年" + dtStart.getMonth()) + "月" + String.valueOf(dtStart.getDay()) + "日";
56
86
 
57
- item.dtStartLong = cur.getLong(cur.getColumnIndex(Events.DTSTART));
58
-
59
- item.setAccountName(cur.getString(cur.getColumnIndex(Events.ACCOUNT_NAME)));
60
-
61
- item.setId(cur.getString(cur.getColumnIndex(Events.CALENDAR_ID)));
62
-
63
- item.setTitle(cur.getString(cur.getColumnIndex(Events.TITLE)));
64
-
65
- item.setDetails(cur.getString(cur.getColumnIndex(Events.DESCRIPTION)));
66
-
67
- item.setOrganizate(cur.getString(cur.getColumnIndex(Events.ORGANIZER)));
68
-
69
- item.setDtStart(new Date(cur.getLong(cur.getColumnIndex(Events.DTSTART))));
70
-
71
- item.setDtEnd(new Date(cur.getLong(cur.getColumnIndex(Events.DTSTART))));
72
-
73
-
74
-
75
- adapter.getItemList().add(item);
76
-
77
- }
87
+ }
78
88
 
79
89
  ```

1

ソースコードを載せました

2018/01/21 11:48

投稿

.Won
.Won

スコア66

test CHANGED
File without changes
test CHANGED
@@ -5,3 +5,75 @@
5
5
 
6
6
 
7
7
  どのようにすればいいですか?
8
+
9
+
10
+
11
+ ```Java
12
+
13
+ final String[] EVENT_PROJECTION = new String[]{
14
+
15
+ Events.CALENDAR_ID,
16
+
17
+ Events.ORGANIZER,
18
+
19
+ Events.ACCOUNT_NAME,
20
+
21
+ Events.TITLE,
22
+
23
+ Events.DESCRIPTION,
24
+
25
+ Events.DTSTART,
26
+
27
+ Events.DTEND
28
+
29
+ };
30
+
31
+
32
+
33
+ ContentResolver cr = getContentResolver();
34
+
35
+ String selection = "(" + Events.ACCOUNT_TYPE + " = ?)";
36
+
37
+ String[] selectionArgs = new String[]{"com.google"};
38
+
39
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
40
+
41
+ return;
42
+
43
+ }
44
+
45
+ Cursor cur = cr.query(Events.CONTENT_URI, EVENT_PROJECTION, null, null, null);
46
+
47
+
48
+
49
+ adapter.getItemList().clear();
50
+
51
+ while(cur.moveToNext()){
52
+
53
+ Toast.makeText(MainActivity.this,cur.getString(cur.getColumnIndex(Events.DTSTART)),Toast.LENGTH_SHORT).show();
54
+
55
+ Item item = new Item();
56
+
57
+ item.dtStartLong = cur.getLong(cur.getColumnIndex(Events.DTSTART));
58
+
59
+ item.setAccountName(cur.getString(cur.getColumnIndex(Events.ACCOUNT_NAME)));
60
+
61
+ item.setId(cur.getString(cur.getColumnIndex(Events.CALENDAR_ID)));
62
+
63
+ item.setTitle(cur.getString(cur.getColumnIndex(Events.TITLE)));
64
+
65
+ item.setDetails(cur.getString(cur.getColumnIndex(Events.DESCRIPTION)));
66
+
67
+ item.setOrganizate(cur.getString(cur.getColumnIndex(Events.ORGANIZER)));
68
+
69
+ item.setDtStart(new Date(cur.getLong(cur.getColumnIndex(Events.DTSTART))));
70
+
71
+ item.setDtEnd(new Date(cur.getLong(cur.getColumnIndex(Events.DTSTART))));
72
+
73
+
74
+
75
+ adapter.getItemList().add(item);
76
+
77
+ }
78
+
79
+ ```