質問編集履歴
4
insert部分の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -213,3 +213,27 @@
|
|
213
213
|
}
|
214
214
|
|
215
215
|
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```
|
220
|
+
|
221
|
+
public static long insert(Context context, DtoItem item) {
|
222
|
+
|
223
|
+
SQLiteDatabase db = getWritableDB(context); // データベース取得
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
ContentValues values = new ContentValues();
|
228
|
+
|
229
|
+
values.put(COLUMN_TITLE, item.title);
|
230
|
+
|
231
|
+
values.put(COLUMN_CONTENTS, item.contents);
|
232
|
+
|
233
|
+
values.put(COLUMN_DATE,item.date);
|
234
|
+
|
235
|
+
return db.insert(TABLE_NAME, null, values);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
```
|
3
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -148,7 +148,7 @@
|
|
148
148
|
|
149
149
|
|
150
150
|
|
151
|
-
|
151
|
+
```
|
152
152
|
|
153
153
|
|
154
154
|
|
2
改行
test
CHANGED
File without changes
|
test
CHANGED
@@ -172,6 +172,8 @@
|
|
172
172
|
|
173
173
|
データベースからとってくるとこのメソッド
|
174
174
|
|
175
|
+
|
176
|
+
|
175
177
|
```
|
176
178
|
|
177
179
|
public static List<DtoItem> findAll(Context context) {
|
1
findallの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -165,3 +165,49 @@
|
|
165
165
|
|
166
166
|
|
167
167
|
itemはid,title,contentsを持っており、idでは正しく表示されました。
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
データベースからとってくるとこのメソッド
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
public static List<DtoItem> findAll(Context context) {
|
178
|
+
|
179
|
+
SQLiteDatabase db = getReadableDB(context); // データベース取得
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
List<DtoItem> listItem = new ArrayList<DtoItem>();
|
184
|
+
|
185
|
+
Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + " order by " + COLUMN_ID, null);
|
186
|
+
|
187
|
+
if (cursor.moveToFirst()) {
|
188
|
+
|
189
|
+
do {
|
190
|
+
|
191
|
+
DtoItem item = new DtoItem();
|
192
|
+
|
193
|
+
item.id = cursor.getLong(0);
|
194
|
+
|
195
|
+
item.title= cursor.getString(1);
|
196
|
+
|
197
|
+
item.contents = cursor.getString(2);
|
198
|
+
|
199
|
+
item.date = cursor.getString(3);
|
200
|
+
|
201
|
+
listItem.add(item);
|
202
|
+
|
203
|
+
} while (cursor.moveToNext());
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
cursor.close();
|
208
|
+
|
209
|
+
return listItem;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
```
|