質問編集履歴
4
insert部分の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -105,4 +105,16 @@
|
|
105
105
|
cursor.close();
|
106
106
|
return listItem;
|
107
107
|
}
|
108
|
+
```
|
109
|
+
|
110
|
+
```
|
111
|
+
public static long insert(Context context, DtoItem item) {
|
112
|
+
SQLiteDatabase db = getWritableDB(context); // データベース取得
|
113
|
+
|
114
|
+
ContentValues values = new ContentValues();
|
115
|
+
values.put(COLUMN_TITLE, item.title);
|
116
|
+
values.put(COLUMN_CONTENTS, item.contents);
|
117
|
+
values.put(COLUMN_DATE,item.date);
|
118
|
+
return db.insert(TABLE_NAME, null, values);
|
119
|
+
}
|
108
120
|
```
|
3
編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -73,7 +73,7 @@
|
|
73
73
|
|
74
74
|
}
|
75
75
|
|
76
|
-
|
76
|
+
```
|
77
77
|
|
78
78
|
このアプリを実行すると
|
79
79
|
|
2
改行
title
CHANGED
File without changes
|
body
CHANGED
@@ -85,6 +85,7 @@
|
|
85
85
|
|
86
86
|
|
87
87
|
データベースからとってくるとこのメソッド
|
88
|
+
|
88
89
|
```
|
89
90
|
public static List<DtoItem> findAll(Context context) {
|
90
91
|
SQLiteDatabase db = getReadableDB(context); // データベース取得
|
1
findallの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -81,4 +81,27 @@
|
|
81
81
|
|
82
82
|
となりデータベースから値がとってこれません。
|
83
83
|
|
84
|
-
itemはid,title,contentsを持っており、idでは正しく表示されました。
|
84
|
+
itemはid,title,contentsを持っており、idでは正しく表示されました。
|
85
|
+
|
86
|
+
|
87
|
+
データベースからとってくるとこのメソッド
|
88
|
+
```
|
89
|
+
public static List<DtoItem> findAll(Context context) {
|
90
|
+
SQLiteDatabase db = getReadableDB(context); // データベース取得
|
91
|
+
|
92
|
+
List<DtoItem> listItem = new ArrayList<DtoItem>();
|
93
|
+
Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + " order by " + COLUMN_ID, null);
|
94
|
+
if (cursor.moveToFirst()) {
|
95
|
+
do {
|
96
|
+
DtoItem item = new DtoItem();
|
97
|
+
item.id = cursor.getLong(0);
|
98
|
+
item.title= cursor.getString(1);
|
99
|
+
item.contents = cursor.getString(2);
|
100
|
+
item.date = cursor.getString(3);
|
101
|
+
listItem.add(item);
|
102
|
+
} while (cursor.moveToNext());
|
103
|
+
}
|
104
|
+
cursor.close();
|
105
|
+
return listItem;
|
106
|
+
}
|
107
|
+
```
|