質問編集履歴
3
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,7 +52,19 @@
|
|
52
52
|
|
53
53
|
```Java
|
54
54
|
|
55
|
-
Insert文
|
55
|
+
Insert文とそこにつながるコード
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
final int price = Integer.parseInt(mPrice.getText().toString());
|
60
|
+
|
61
|
+
final String category = (String) gCategory.getSelectedItem();
|
62
|
+
|
63
|
+
final String memo = gMemo.getText().toString();
|
64
|
+
|
65
|
+
final String date = gDate.getText().toString();
|
66
|
+
|
67
|
+
insertData(db, price, category, memo, date);
|
56
68
|
|
57
69
|
|
58
70
|
|
2
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -348,73 +348,7 @@
|
|
348
348
|
|
349
349
|
if (_id == cursor.getInt(3)) {
|
350
350
|
|
351
|
-
int index = 0;
|
352
|
-
|
353
|
-
category = cursor.getString(0);
|
354
|
-
|
355
|
-
switch (category) {
|
356
|
-
|
357
|
-
case "食費":
|
358
|
-
|
359
|
-
index = 0;
|
360
|
-
|
361
|
-
|
351
|
+
~中略~
|
362
|
-
|
363
|
-
case "日用品":
|
364
|
-
|
365
|
-
index = 1;
|
366
|
-
|
367
|
-
break;
|
368
|
-
|
369
|
-
case "教育費":
|
370
|
-
|
371
|
-
index = 2;
|
372
|
-
|
373
|
-
break;
|
374
|
-
|
375
|
-
case "習い事":
|
376
|
-
|
377
|
-
index = 3;
|
378
|
-
|
379
|
-
break;
|
380
|
-
|
381
|
-
case "娯楽費":
|
382
|
-
|
383
|
-
index = 4;
|
384
|
-
|
385
|
-
break;
|
386
|
-
|
387
|
-
case "その他支出":
|
388
|
-
|
389
|
-
index = 5;
|
390
|
-
|
391
|
-
break;
|
392
|
-
|
393
|
-
case "収入":
|
394
|
-
|
395
|
-
index = 6;
|
396
|
-
|
397
|
-
break;
|
398
|
-
|
399
|
-
case "その他収入":
|
400
|
-
|
401
|
-
index = 7;
|
402
|
-
|
403
|
-
break;
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
categoryView.setSelection(index);
|
408
|
-
|
409
|
-
memo = cursor.getString(1);
|
410
|
-
|
411
|
-
price = cursor.getString(2);
|
412
|
-
|
413
|
-
memoView.setText(memo);
|
414
|
-
|
415
|
-
priceView.setText(price);
|
416
|
-
|
417
|
-
dateView.setText(date);
|
418
352
|
|
419
353
|
}
|
420
354
|
|
1
データソースの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -201,3 +201,235 @@
|
|
201
201
|
}
|
202
202
|
|
203
203
|
```
|
204
|
+
|
205
|
+
```Java
|
206
|
+
|
207
|
+
idをどうくらべているか
|
208
|
+
|
209
|
+
Cursor cursor = db.query(
|
210
|
+
|
211
|
+
"kakeibodb",
|
212
|
+
|
213
|
+
new String[] {"category", "memo", "price", "_id"},
|
214
|
+
|
215
|
+
"date=?",
|
216
|
+
|
217
|
+
new String[] {date},
|
218
|
+
|
219
|
+
null,
|
220
|
+
|
221
|
+
null,
|
222
|
+
|
223
|
+
null);
|
224
|
+
|
225
|
+
boolean next = cursor.moveToFirst();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
while (next) {
|
230
|
+
|
231
|
+
Daily daily = new Daily();
|
232
|
+
|
233
|
+
daily.setCategory(cursor.getString(0));// categoryを取得
|
234
|
+
|
235
|
+
daily.setMemo(cursor.getString(1));// memoを取得
|
236
|
+
|
237
|
+
daily.setPrice(String.valueOf(cursor.getInt(2)));// priceを取得
|
238
|
+
|
239
|
+
daily.set_id(cursor.getInt(3));//IDを取得
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
// 次の行が存在するか確認
|
244
|
+
|
245
|
+
next = cursor.moveToNext();
|
246
|
+
|
247
|
+
dataset.add(daily);
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
↓
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
public class Daily {
|
258
|
+
|
259
|
+
long id;
|
260
|
+
|
261
|
+
private String category;
|
262
|
+
|
263
|
+
private String memo;
|
264
|
+
|
265
|
+
private String price;
|
266
|
+
|
267
|
+
private int _id;
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
~中略~
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
public int get_id() {
|
278
|
+
|
279
|
+
return _id;
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
public void set_id(int _id) {
|
286
|
+
|
287
|
+
this._id = _id;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
↓
|
296
|
+
|
297
|
+
dailyListに格納して一覧表示のうち選択された行のポジションのIdを取得、Intentによる受け渡し
|
298
|
+
|
299
|
+
int _id = dailyList.get(position).get_id();
|
300
|
+
|
301
|
+
Intent intent = new Intent(getApplication(), Delete.class);
|
302
|
+
|
303
|
+
intent.putExtra("ID", _id);
|
304
|
+
|
305
|
+
startActivity(intent);
|
306
|
+
|
307
|
+
↓
|
308
|
+
|
309
|
+
Delete Class
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
int _id = intent.getIntExtra("ID", 0);
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
kDB = new KakeiboDatabase(getApplicationContext());
|
318
|
+
|
319
|
+
SQLiteDatabase db = kDB.getReadableDatabase();
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
String category, memo;
|
324
|
+
|
325
|
+
String price = "";
|
326
|
+
|
327
|
+
Cursor cursor = db.query(
|
328
|
+
|
329
|
+
"kakeibodb",
|
330
|
+
|
331
|
+
new String[]{"category", "memo", "price", "_id"},
|
332
|
+
|
333
|
+
"date=?",
|
334
|
+
|
335
|
+
new String[]{date},
|
336
|
+
|
337
|
+
null,
|
338
|
+
|
339
|
+
null,
|
340
|
+
|
341
|
+
null);
|
342
|
+
|
343
|
+
boolean next = cursor.moveToFirst();
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
while (next) {
|
348
|
+
|
349
|
+
if (_id == cursor.getInt(3)) {
|
350
|
+
|
351
|
+
int index = 0;
|
352
|
+
|
353
|
+
category = cursor.getString(0);
|
354
|
+
|
355
|
+
switch (category) {
|
356
|
+
|
357
|
+
case "食費":
|
358
|
+
|
359
|
+
index = 0;
|
360
|
+
|
361
|
+
break;
|
362
|
+
|
363
|
+
case "日用品":
|
364
|
+
|
365
|
+
index = 1;
|
366
|
+
|
367
|
+
break;
|
368
|
+
|
369
|
+
case "教育費":
|
370
|
+
|
371
|
+
index = 2;
|
372
|
+
|
373
|
+
break;
|
374
|
+
|
375
|
+
case "習い事":
|
376
|
+
|
377
|
+
index = 3;
|
378
|
+
|
379
|
+
break;
|
380
|
+
|
381
|
+
case "娯楽費":
|
382
|
+
|
383
|
+
index = 4;
|
384
|
+
|
385
|
+
break;
|
386
|
+
|
387
|
+
case "その他支出":
|
388
|
+
|
389
|
+
index = 5;
|
390
|
+
|
391
|
+
break;
|
392
|
+
|
393
|
+
case "収入":
|
394
|
+
|
395
|
+
index = 6;
|
396
|
+
|
397
|
+
break;
|
398
|
+
|
399
|
+
case "その他収入":
|
400
|
+
|
401
|
+
index = 7;
|
402
|
+
|
403
|
+
break;
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
categoryView.setSelection(index);
|
408
|
+
|
409
|
+
memo = cursor.getString(1);
|
410
|
+
|
411
|
+
price = cursor.getString(2);
|
412
|
+
|
413
|
+
memoView.setText(memo);
|
414
|
+
|
415
|
+
priceView.setText(price);
|
416
|
+
|
417
|
+
dateView.setText(date);
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
// 次の行が存在するか確認
|
422
|
+
|
423
|
+
next = cursor.moveToNext();
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
cursor.close();
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
```
|