質問編集履歴

9

誤字

2017/04/24 08:07

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -70,9 +70,9 @@
70
70
 
71
71
  TextView textView = (TextView) findViewById(R.id.body);
72
72
 
73
- String ccc="残りは100です。";
73
+ String nokko="残りは100です。";
74
-
74
+
75
- textView.setText(ccc);
75
+ textView.setText(noko);
76
76
 
77
77
 
78
78
 

8

doge

2017/04/24 08:07

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -488,7 +488,7 @@
488
488
 
489
489
  public static final String TABLE_NAME="body";
490
490
 
491
- public static final String TABLE_NAME1="new1";
491
+ public static final String TABLE_NAME1="doge";
492
492
 
493
493
  public static final String COL_HP="hp";
494
494
 

7

ついあk

2017/04/24 05:00

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,12 @@
26
26
 
27
27
  ```java
28
28
 
29
+ /**
30
+
31
+ se=select 、up=update 、in=insert、bd=body(体力)、cobo=countbody 、stcobo=string count body、hp=100-body 、stringbody=string.valueOf(hp)
32
+
33
+ **/
34
+
29
35
 
30
36
 
31
37
  import static com.example.android.sample.physicalstrength.Databaseset.CREATE_TABLE;

6

みいいやすく

2017/04/24 02:10

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  int body = 2;
46
46
 
47
- int j=0;
47
+ int cobo=0;
48
48
 
49
49
  boolean zzz=false;
50
50
 
@@ -130,13 +130,13 @@
130
130
 
131
131
 
132
132
 
133
- j =body++;
133
+ cobo =body++;
134
-
134
+
135
- String hp = String.valueOf(j);
135
+ String stcobo = String.valueOf(cobo);
136
-
137
-
138
-
136
+
137
+
138
+
139
- String sql = "INSERT INTO " + table + "(hp,data) " + "VALUES('" + hp + "','" + data + "')";
139
+ String sql = "INSERT INTO " + table + "(hp,data) " + "VALUES('" + stcobo + "','" + data + "')";
140
140
 
141
141
 
142
142
 
@@ -146,25 +146,25 @@
146
146
 
147
147
  //Activityで、データベースから取得した値がnew ならばoldにする、そして、データベースに集計を入れる。
148
148
 
149
- String aaa=null;
149
+ String stringhp=null;
150
-
150
+
151
- Log.v("insertしてるやつ",hp+" : "+data);
151
+ Log.v("insertしてるやつ",stcobo+" : "+data);
152
-
152
+
153
- int a = 100 - j;
153
+ int hp = 100 - cobo;
154
-
155
-
156
-
154
+
155
+
156
+
157
- if(a > 0) {
157
+ if(hp > 0) {
158
-
158
+
159
- aaa = "残りは" + a + "です。";
159
+ stringhp = "残りは" + hp + "です。";
160
-
160
+
161
- }else if(a==0){
161
+ }else if(hp==0){
162
-
162
+
163
- aaa = "もう" + a + "です。";
163
+ stringhp = "もう" + hp + "です。";
164
164
 
165
165
  }else {
166
166
 
167
- aaa = a + "になっています。";
167
+ stringhp = hp + "になっています。";
168
168
 
169
169
  }
170
170
 
@@ -172,7 +172,7 @@
172
172
 
173
173
  TextView textView = (TextView) findViewById(R.id.body);
174
174
 
175
- textView.setText(aaa);
175
+ textView.setText(stringhp);
176
176
 
177
177
 
178
178
 
@@ -218,330 +218,336 @@
218
218
 
219
219
 
220
220
 
221
+ ////////
222
+
223
+ // String insert="insert into "+table1+" (doge) values('true')";
224
+
225
+ // Log.v("insert////",insert);
226
+
227
+
228
+
229
+
230
+
231
+ String select = "select * from "+table1;
232
+
233
+ Log.v("select////",select);
234
+
235
+
236
+
237
+ //////////
238
+
239
+ // Cursor in=db.rawQuery(insert,null);
240
+
241
+ //このinを何かに使わなきゃいけないんじゃなかったっけ?
242
+
243
+
244
+
245
+
246
+
247
+ Cursor se = db.rawQuery(select, null);
248
+
249
+
250
+
251
+
252
+
253
+ String doge="false";
254
+
255
+
256
+
257
+
258
+
259
+ //ここではいれてない
260
+
261
+ boolean isEof = se.moveToFirst();
262
+
263
+ Log.d("Before Cursor Position/","" + se.getPosition());
264
+
265
+ se.moveToNext();
266
+
267
+ Log.d("Before Cursor Position/","" + se.getPosition());
268
+
269
+ // / データを取得していく
270
+
271
+ while(isEof) {
272
+
273
+ doge = se.getString(se.getColumnIndex(Usersdata.Users.DOGE));
274
+
275
+ Log.v("if入る前Acti:",doge);
276
+
277
+ }
278
+
279
+
280
+
281
+ if(doge=="true"){
282
+
283
+ //trueになってたら、Serviceでtrueにしたってこと
284
+
285
+
286
+
287
+ body=0;
288
+
289
+ Log.v("Maでtrueだったため、if文に入る :",doge);
290
+
291
+ String update="update "+table1+" set doge='false'";
292
+
293
+ Cursor up=db.rawQuery(update,null);
294
+
295
+
296
+
297
+ //trueってことは、24時間たったってことだからbzを0にして体力回復させる
298
+
299
+ body=0;
300
+
301
+
302
+
303
+ String bd=String.valueOf(body);
304
+
305
+ Log.v("bodyは0になるはずなのに",bd);
306
+
307
+
308
+
309
+ }
310
+
311
+ se.close();
312
+
313
+ db.close();
314
+
315
+
316
+
317
+
318
+
319
+ //
320
+
321
+ int aaa=10;
322
+
323
+ int bbb=39;
324
+
325
+ addReset(aaa,bbb);
326
+
327
+ getPendingIntent();
328
+
329
+
330
+
331
+ }
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+ private static final String TAG = MainActivity.class.getSimpleName();
342
+
343
+
344
+
345
+ //Resetのコード
346
+
347
+ public void addReset(int resetHour, int resetMinute) {
348
+
349
+
350
+
351
+ // Reset(リセット)を設定する
352
+
353
+ PendingIntent mResetSender = this.getPendingIntent();
354
+
355
+
356
+
357
+ // リセットするメソッドを呼ぶ時間の設定
358
+
359
+ java.util.Calendar cal = java.util.Calendar.getInstance();
360
+
361
+ cal.setTimeInMillis(System.currentTimeMillis());
362
+
363
+ // 設定した時刻をカレンダーに設定
364
+
365
+ cal.set(cal.HOUR_OF_DAY, resetHour);
366
+
367
+ cal.set(cal.MINUTE, resetMinute);
368
+
369
+ cal.set(cal.SECOND, 0);
370
+
371
+ cal.set(cal.MILLISECOND, 0);
372
+
373
+
374
+
375
+ Toast.makeText(this, String.format("%d時%d分にtoast表示のメソッドを呼びます", resetHour, resetMinute), Toast.LENGTH_LONG).show();
376
+
377
+
378
+
379
+ // AlramManager取得
380
+
381
+ AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
382
+
383
+ // AlarmManagerにPendingIntentを登録
384
+
385
+ am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), mResetSender);
386
+
387
+
388
+
389
+
390
+
391
+ Log.v(TAG, cal.getTimeInMillis() + "ms");
392
+
393
+ Log.v(TAG, "2:30に表示するメソッドを呼ぶ、セット完了");
394
+
395
+ }
396
+
397
+ private PendingIntent getPendingIntent() {
398
+
399
+ Intent intent = new Intent(this, MyResetService.class);
400
+
401
+
402
+
403
+ //このintentにクラス変数の値をsetし、Serviceでデータベースにセットする。
404
+
405
+
406
+
407
+ String stcobo=String.valueOf(cobo);
408
+
409
+
410
+
411
+ Log.v("xxxxxxxxxx",stcobo);
412
+
413
+
414
+
415
+ PendingIntent pendingIntent = PendingIntent.getService(this, PendingIntent.FLAG_ONE_SHOT, intent, PendingIntent.FLAG_UPDATE_CURRENT);
416
+
417
+ return pendingIntent;
418
+
419
+
420
+
421
+ }
422
+
423
+
424
+
425
+ }
426
+
427
+
428
+
429
+
430
+
431
+ ```
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+ //Usersdata
442
+
443
+ ```java
444
+
445
+ package com.example.android.sample.physicalstrength;
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+ import android.provider.BaseColumns;
454
+
455
+
456
+
457
+ /**
458
+
459
+ * Created by endoutaichi on 2017/04/22.
460
+
461
+ */
462
+
463
+
464
+
465
+ public class Usersdata {
466
+
467
+
468
+
469
+ public Usersdata(){}
470
+
471
+
472
+
473
+ public static abstract class Users implements BaseColumns {
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+ public static final String _ID="id";
482
+
483
+ public static final String TABLE_NAME="body";
484
+
485
+ public static final String TABLE_NAME1="new1";
486
+
487
+ public static final String COL_HP="hp";
488
+
489
+ public static final String COL_DATA="data";
490
+
491
+
492
+
493
+ public static final String DOGE="doge";
494
+
495
+
496
+
497
+
498
+
499
+ }
500
+
501
+ }
502
+
503
+ ```
504
+
505
+ //Databaseset
506
+
507
+ ```java
508
+
509
+
510
+
511
+ public class Databaseset extends SQLiteOpenHelper {
512
+
513
+
514
+
515
+
516
+
517
+ public static final String DB_NAME="bodyhp.db";
518
+
519
+ public static final int DB_VERSION=2;
520
+
521
+
522
+
523
+ public static final String CREATE_TABLE=
524
+
525
+ "create table " + Usersdata.Users.TABLE_NAME + "(" +
526
+
527
+ Usersdata.Users._ID + " integer primary key autoincrement, " +
528
+
529
+ Usersdata.Users.COL_HP + " text, " +
530
+
531
+ Usersdata.Users.COL_DATA + " text)";
532
+
533
+
534
+
535
+ public static final String CREATE_TABLE1=
536
+
537
+ "create table "+Usersdata.Users.TABLE_NAME1+"("+
538
+
539
+ Usersdata.Users.DOGE+" text )";
540
+
541
+
542
+
543
+
544
+
545
+
546
+
221
547
 
222
548
 
223
- // String insert="insert into "+table1+" (doge) values('true')";
224
-
225
- // Log.v("insert////",insert);
226
-
227
-
228
-
229
-
230
-
231
- String select = "select * from "+table1;
232
-
233
- Log.v("select////",select);
234
-
235
-
236
-
237
- // Cursor in=db.rawQuery(insert,null);
238
-
239
- //このinを何かに使わなきゃいけないんじゃなかったっけ?
240
-
241
-
242
-
243
-
244
-
245
- Cursor se = db.rawQuery(select, null);
246
-
247
-
248
-
249
-
250
-
251
- String doge="false";
252
-
253
-
254
-
255
-
256
-
257
- //ここではいれてない
258
-
259
- boolean isEof = se.moveToFirst();
260
-
261
- Log.d("Before Cursor Position/","" + se.getPosition());
262
-
263
- se.moveToNext();
264
-
265
- Log.d("Before Cursor Position/","" + se.getPosition());
266
-
267
- // / データを取得していく
268
-
269
- while(isEof) {
270
-
271
- doge = se.getString(se.getColumnIndex(Usersdata.Users.DOGE));
272
-
273
- Log.v("if入る前Acti:",doge);
274
-
275
- }
276
-
277
-
278
-
279
- if(doge=="true"){
280
-
281
- //trueになってたら、Serviceでtrueにしたってこと
282
-
283
-
284
-
285
- body=0;
286
-
287
- Log.v("Maでtrueだったため、if文に入る :",doge);
288
-
289
- String update="update "+table1+" set doge='false'";
290
-
291
- Cursor up=db.rawQuery(update,null);
292
-
293
-
294
-
295
- //trueってことは、24時間たったってことだからbzを0にして体力回復させる
296
-
297
- body=0;
298
-
299
-
300
-
301
- String bd=String.valueOf(body);
302
-
303
- Log.v("bodyは0になるはずなのに",bd);
304
-
305
-
306
-
307
- }
308
-
309
- se.close();
310
-
311
- db.close();
312
-
313
-
314
-
315
-
316
-
317
- //ここで、メソッドを呼ぶ
318
-
319
- int aaa=10;
320
-
321
- int bbb=39;
322
-
323
- addReset(aaa,bbb);
324
-
325
- getPendingIntent();
326
-
327
-
328
-
329
549
  }
330
550
 
331
551
 
332
552
 
333
-
334
-
335
-
336
-
337
-
338
-
339
- private static final String TAG = MainActivity.class.getSimpleName();
340
-
341
-
342
-
343
- //Resetのコード
344
-
345
- public void addReset(int resetHour, int resetMinute) {
346
-
347
-
348
-
349
- // Reset(リセット)を設定する
350
-
351
- PendingIntent mResetSender = this.getPendingIntent();
352
-
353
-
354
-
355
- // リセットするメソッドを呼ぶ時間の設定
356
-
357
- java.util.Calendar cal = java.util.Calendar.getInstance();
358
-
359
- cal.setTimeInMillis(System.currentTimeMillis());
360
-
361
- // 設定した時刻をカレンダーに設定
362
-
363
- cal.set(cal.HOUR_OF_DAY, resetHour);
364
-
365
- cal.set(cal.MINUTE, resetMinute);
366
-
367
- cal.set(cal.SECOND, 0);
368
-
369
- cal.set(cal.MILLISECOND, 0);
370
-
371
-
372
-
373
- Toast.makeText(this, String.format("%d時%d分にtoast表示のメソッドを呼びます", resetHour, resetMinute), Toast.LENGTH_LONG).show();
374
-
375
-
376
-
377
- // AlramManager取得
378
-
379
- AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
380
-
381
- // AlarmManagerにPendingIntentを登録
382
-
383
- am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), mResetSender);
384
-
385
-
386
-
387
-
388
-
389
- Log.v(TAG, cal.getTimeInMillis() + "ms");
390
-
391
- Log.v(TAG, "2:30に表示するメソッドを呼ぶ、セット完了");
392
-
393
- }
394
-
395
- private PendingIntent getPendingIntent() {
396
-
397
- Intent intent = new Intent(this, MyResetService.class);
398
-
399
-
400
-
401
- //このintentにクラス変数の値をsetし、Serviceでデータベースにセットする。
402
-
403
-
404
-
405
- String a=String.valueOf(j);
406
-
407
-
408
-
409
- Log.v("xxxxxxxxxx",a);
410
-
411
-
412
-
413
- PendingIntent pendingIntent = PendingIntent.getService(this, PendingIntent.FLAG_ONE_SHOT, intent, PendingIntent.FLAG_UPDATE_CURRENT);
414
-
415
- return pendingIntent;
416
-
417
-
418
-
419
- }
420
-
421
-
422
-
423
- }
424
-
425
553
  ```
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
- //Usersdata
436
-
437
- ```java
438
-
439
- package com.example.android.sample.physicalstrength;
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
- import android.provider.BaseColumns;
448
-
449
-
450
-
451
- /**
452
-
453
- * Created by endoutaichi on 2017/04/22.
454
-
455
- */
456
-
457
-
458
-
459
- public class Usersdata {
460
-
461
-
462
-
463
- public Usersdata(){}
464
-
465
-
466
-
467
- public static abstract class Users implements BaseColumns {
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
- public static final String _ID="id";
476
-
477
- public static final String TABLE_NAME="body";
478
-
479
- public static final String TABLE_NAME1="new1";
480
-
481
- public static final String COL_HP="hp";
482
-
483
- public static final String COL_DATA="data";
484
-
485
-
486
-
487
- public static final String DOGE="doge";
488
-
489
-
490
-
491
-
492
-
493
- }
494
-
495
- }
496
-
497
- ```
498
-
499
- //Databaseset
500
-
501
- ```java
502
-
503
-
504
-
505
- public class Databaseset extends SQLiteOpenHelper {
506
-
507
-
508
-
509
-
510
-
511
- public static final String DB_NAME="bodyhp.db";
512
-
513
- public static final int DB_VERSION=2;
514
-
515
-
516
-
517
- public static final String CREATE_TABLE=
518
-
519
- "create table " + Usersdata.Users.TABLE_NAME + "(" +
520
-
521
- Usersdata.Users._ID + " integer primary key autoincrement, " +
522
-
523
- Usersdata.Users.COL_HP + " text, " +
524
-
525
- Usersdata.Users.COL_DATA + " text)";
526
-
527
-
528
-
529
- public static final String CREATE_TABLE1=
530
-
531
- "create table "+Usersdata.Users.TABLE_NAME1+"("+
532
-
533
- Usersdata.Users.DOGE+" text )";
534
-
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
- }
544
-
545
-
546
-
547
- ```

5

ついか

2017/04/24 02:08

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -421,3 +421,127 @@
421
421
 
422
422
 
423
423
  }
424
+
425
+ ```
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+ //Usersdata
436
+
437
+ ```java
438
+
439
+ package com.example.android.sample.physicalstrength;
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+ import android.provider.BaseColumns;
448
+
449
+
450
+
451
+ /**
452
+
453
+ * Created by endoutaichi on 2017/04/22.
454
+
455
+ */
456
+
457
+
458
+
459
+ public class Usersdata {
460
+
461
+
462
+
463
+ public Usersdata(){}
464
+
465
+
466
+
467
+ public static abstract class Users implements BaseColumns {
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+ public static final String _ID="id";
476
+
477
+ public static final String TABLE_NAME="body";
478
+
479
+ public static final String TABLE_NAME1="new1";
480
+
481
+ public static final String COL_HP="hp";
482
+
483
+ public static final String COL_DATA="data";
484
+
485
+
486
+
487
+ public static final String DOGE="doge";
488
+
489
+
490
+
491
+
492
+
493
+ }
494
+
495
+ }
496
+
497
+ ```
498
+
499
+ //Databaseset
500
+
501
+ ```java
502
+
503
+
504
+
505
+ public class Databaseset extends SQLiteOpenHelper {
506
+
507
+
508
+
509
+
510
+
511
+ public static final String DB_NAME="bodyhp.db";
512
+
513
+ public static final int DB_VERSION=2;
514
+
515
+
516
+
517
+ public static final String CREATE_TABLE=
518
+
519
+ "create table " + Usersdata.Users.TABLE_NAME + "(" +
520
+
521
+ Usersdata.Users._ID + " integer primary key autoincrement, " +
522
+
523
+ Usersdata.Users.COL_HP + " text, " +
524
+
525
+ Usersdata.Users.COL_DATA + " text)";
526
+
527
+
528
+
529
+ public static final String CREATE_TABLE1=
530
+
531
+ "create table "+Usersdata.Users.TABLE_NAME1+"("+
532
+
533
+ Usersdata.Users.DOGE+" text )";
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+ }
544
+
545
+
546
+
547
+ ```

4

みやすく

2017/04/24 01:54

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -421,121 +421,3 @@
421
421
 
422
422
 
423
423
  }
424
-
425
-
426
-
427
-
428
-
429
- //Usersdata
430
-
431
- ```java
432
-
433
- package com.example.android.sample.physicalstrength;
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
- import android.provider.BaseColumns;
442
-
443
-
444
-
445
- /**
446
-
447
- * Created by endoutaichi on 2017/04/22.
448
-
449
- */
450
-
451
-
452
-
453
- public class Usersdata {
454
-
455
-
456
-
457
- public Usersdata(){}
458
-
459
-
460
-
461
- public static abstract class Users implements BaseColumns {
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
- public static final String _ID="id";
470
-
471
- public static final String TABLE_NAME="body";
472
-
473
- public static final String TABLE_NAME1="new1";
474
-
475
- public static final String COL_HP="hp";
476
-
477
- public static final String COL_DATA="data";
478
-
479
-
480
-
481
- public static final String DOGE="doge";
482
-
483
-
484
-
485
-
486
-
487
- }
488
-
489
- }
490
-
491
- ```
492
-
493
- //Databaseset
494
-
495
- ```java
496
-
497
-
498
-
499
- public class Databaseset extends SQLiteOpenHelper {
500
-
501
-
502
-
503
-
504
-
505
- public static final String DB_NAME="bodyhp.db";
506
-
507
- public static final int DB_VERSION=2;
508
-
509
-
510
-
511
- public static final String CREATE_TABLE=
512
-
513
- "create table " + Usersdata.Users.TABLE_NAME + "(" +
514
-
515
- Usersdata.Users._ID + " integer primary key autoincrement, " +
516
-
517
- Usersdata.Users.COL_HP + " text, " +
518
-
519
- Usersdata.Users.COL_DATA + " text)";
520
-
521
-
522
-
523
- public static final String CREATE_TABLE1=
524
-
525
- "create table "+Usersdata.Users.TABLE_NAME1+"("+
526
-
527
- Usersdata.Users.DOGE+" text )";
528
-
529
-
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
- }
538
-
539
-
540
-
541
- ```

3

コードをきれいに

2017/04/24 01:53

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -538,6 +538,4 @@
538
538
 
539
539
 
540
540
 
541
-
542
-
543
541
  ```

2

コードを綺麗にしました。

2017/04/24 01:51

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,8 @@
26
26
 
27
27
  ```java
28
28
 
29
+
30
+
29
31
  import static com.example.android.sample.physicalstrength.Databaseset.CREATE_TABLE;
30
32
 
31
33
 
@@ -40,7 +42,7 @@
40
42
 
41
43
 
42
44
 
43
- int bz = 2;
45
+ int body = 2;
44
46
 
45
47
  int j=0;
46
48
 
@@ -80,9 +82,9 @@
80
82
 
81
83
  //コメントアウトしてる
82
84
 
83
- //db.execSQL(CREATE_TABLE);
85
+ // db.execSQL(CREATE_TABLE);
84
-
86
+
85
- // db.execSQL(CREATE_TABLE1);
87
+ // db.execSQL(CREATE_TABLE1);
86
88
 
87
89
 
88
90
 
@@ -128,7 +130,7 @@
128
130
 
129
131
 
130
132
 
131
- j = bz++;
133
+ j =body++;
132
134
 
133
135
  String hp = String.valueOf(j);
134
136
 
@@ -138,6 +140,12 @@
138
140
 
139
141
 
140
142
 
143
+
144
+
145
+ ///Serviceで、update文で、id 1の、データのdataをStringがたのoldにして、
146
+
147
+ //Activityで、データベースから取得した値がnew ならばoldにする、そして、データベースに集計を入れる。
148
+
141
149
  String aaa=null;
142
150
 
143
151
  Log.v("insertしてるやつ",hp+" : "+data);
@@ -180,450 +188,356 @@
180
188
 
181
189
 
182
190
 
191
+ }
192
+
193
+
194
+
195
+
196
+
197
+ @Override
198
+
199
+ public void onStart(){
200
+
201
+ super.onStart();
202
+
203
+
204
+
205
+ String x="まじで";Log.v("ここに一点の?",x);
206
+
207
+
208
+
209
+ SQLiteDatabase db = null;
210
+
211
+ Databaseset databaseset = new Databaseset(MainActivity.this);
212
+
213
+ db = databaseset.getWritableDatabase();
214
+
215
+
216
+
217
+ String table1 = Usersdata.Users.TABLE_NAME1;
218
+
219
+
220
+
221
+
222
+
223
+ // String insert="insert into "+table1+" (doge) values('true')";
224
+
225
+ // Log.v("insert////",insert);
226
+
227
+
228
+
229
+
230
+
231
+ String select = "select * from "+table1;
232
+
233
+ Log.v("select////",select);
234
+
235
+
236
+
237
+ // Cursor in=db.rawQuery(insert,null);
238
+
239
+ //このinを何かに使わなきゃいけないんじゃなかったっけ?
240
+
241
+
242
+
243
+
244
+
245
+ Cursor se = db.rawQuery(select, null);
246
+
247
+
248
+
249
+
250
+
251
+ String doge="false";
252
+
253
+
254
+
255
+
256
+
183
- //8:00にset
257
+ //ここではいれてない
258
+
184
-
259
+ boolean isEof = se.moveToFirst();
260
+
261
+ Log.d("Before Cursor Position/","" + se.getPosition());
262
+
263
+ se.moveToNext();
264
+
265
+ Log.d("Before Cursor Position/","" + se.getPosition());
266
+
267
+ // / データを取得していく
268
+
269
+ while(isEof) {
270
+
271
+ doge = se.getString(se.getColumnIndex(Usersdata.Users.DOGE));
272
+
273
+ Log.v("if入る前Acti:",doge);
274
+
275
+ }
276
+
277
+
278
+
279
+ if(doge=="true"){
280
+
281
+ //trueになってたら、Serviceでtrueにしたってこと
282
+
283
+
284
+
285
+ body=0;
286
+
287
+ Log.v("Maでtrueだったため、if文に入る :",doge);
288
+
289
+ String update="update "+table1+" set doge='false'";
290
+
291
+ Cursor up=db.rawQuery(update,null);
292
+
293
+
294
+
295
+ //trueってことは、24時間たったってことだからbzを0にして体力回復させる
296
+
297
+ body=0;
298
+
299
+
300
+
301
+ String bd=String.valueOf(body);
302
+
303
+ Log.v("bodyは0になるはずなのに",bd);
304
+
305
+
306
+
307
+ }
308
+
309
+ se.close();
310
+
311
+ db.close();
312
+
313
+
314
+
315
+
316
+
317
+ //ここで、メソッドを呼ぶ
318
+
185
- int aaa=8;
319
+ int aaa=10;
186
-
320
+
187
- int bbb=0;
321
+ int bbb=39;
188
322
 
189
323
  addReset(aaa,bbb);
190
324
 
191
325
  getPendingIntent();
192
326
 
327
+
328
+
193
329
  }
194
330
 
195
331
 
196
332
 
333
+
334
+
335
+
336
+
337
+
338
+
339
+ private static final String TAG = MainActivity.class.getSimpleName();
340
+
341
+
342
+
343
+ //Resetのコード
344
+
345
+ public void addReset(int resetHour, int resetMinute) {
346
+
347
+
348
+
349
+ // Reset(リセット)を設定する
350
+
351
+ PendingIntent mResetSender = this.getPendingIntent();
352
+
353
+
354
+
355
+ // リセットするメソッドを呼ぶ時間の設定
356
+
357
+ java.util.Calendar cal = java.util.Calendar.getInstance();
358
+
359
+ cal.setTimeInMillis(System.currentTimeMillis());
360
+
361
+ // 設定した時刻をカレンダーに設定
362
+
363
+ cal.set(cal.HOUR_OF_DAY, resetHour);
364
+
365
+ cal.set(cal.MINUTE, resetMinute);
366
+
367
+ cal.set(cal.SECOND, 0);
368
+
369
+ cal.set(cal.MILLISECOND, 0);
370
+
371
+
372
+
373
+ Toast.makeText(this, String.format("%d時%d分にtoast表示のメソッドを呼びます", resetHour, resetMinute), Toast.LENGTH_LONG).show();
374
+
375
+
376
+
377
+ // AlramManager取得
378
+
379
+ AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
380
+
381
+ // AlarmManagerにPendingIntentを登録
382
+
383
+ am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), mResetSender);
384
+
385
+
386
+
387
+
388
+
389
+ Log.v(TAG, cal.getTimeInMillis() + "ms");
390
+
391
+ Log.v(TAG, "2:30に表示するメソッドを呼ぶ、セット完了");
392
+
393
+ }
394
+
395
+ private PendingIntent getPendingIntent() {
396
+
397
+ Intent intent = new Intent(this, MyResetService.class);
398
+
399
+
400
+
401
+ //このintentにクラス変数の値をsetし、Serviceでデータベースにセットする。
402
+
403
+
404
+
405
+ String a=String.valueOf(j);
406
+
407
+
408
+
409
+ Log.v("xxxxxxxxxx",a);
410
+
411
+
412
+
413
+ PendingIntent pendingIntent = PendingIntent.getService(this, PendingIntent.FLAG_ONE_SHOT, intent, PendingIntent.FLAG_UPDATE_CURRENT);
414
+
415
+ return pendingIntent;
416
+
417
+
418
+
419
+ }
420
+
421
+
422
+
423
+ }
424
+
425
+
426
+
427
+
428
+
429
+ //Usersdata
430
+
431
+ ```java
432
+
433
+ package com.example.android.sample.physicalstrength;
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+ import android.provider.BaseColumns;
442
+
443
+
444
+
197
- @Override
445
+ /**
446
+
198
-
447
+ * Created by endoutaichi on 2017/04/22.
448
+
449
+ */
450
+
451
+
452
+
453
+ public class Usersdata {
454
+
455
+
456
+
199
- public void onStart(){
457
+ public Usersdata(){}
200
-
458
+
459
+
460
+
201
- super.onStart();
461
+ public static abstract class Users implements BaseColumns {
462
+
463
+
464
+
465
+
202
466
 
203
467
 
204
468
 
205
-
206
-
207
- SQLiteDatabase db = null;
208
-
209
- Databaseset databaseset = new Databaseset(MainActivity.this);
210
-
211
- db = databaseset.getWritableDatabase();
469
+ public static final String _ID="id";
470
+
212
-
471
+ public static final String TABLE_NAME="body";
213
-
214
-
472
+
215
- String table1 = Usersdata.Users.TABLE_NAME1;
473
+ public static final String TABLE_NAME1="new1";
216
-
217
- String sql1="insert into "+table1+"(doge) values('true')";
474
+
218
-
219
- String sql = "select * from "+table1;
475
+ public static final String COL_HP="hp";
220
-
221
-
222
-
223
- Cursor cd=db.rawQuery(sql1,null);
476
+
224
-
225
- Cursor ca = db.rawQuery(sql, null);
477
+ public static final String COL_DATA="data";
226
-
227
-
228
-
229
-
230
-
478
+
479
+
480
+
231
- String doge="false";
481
+ public static final String DOGE="doge";
232
-
233
- bz=0;
482
+
234
-
235
-
236
-
237
- //ここではいれてない
483
+
238
-
239
- boolean isEof = ca.moveToFirst();
240
-
241
- // データを取得していく
242
-
243
- while(isEof) {
244
-
245
- doge = ca.getString(ca.getColumnIndex(Usersdata.Users.DOGE));
246
-
247
- Log.v("if入る前Acti:",doge);
248
-
249
- }
250
-
251
-
252
-
253
- if(doge=="true"){
254
-
255
- //trueになってたら、Serviceでtrueにしたってこと
256
-
257
-
258
-
259
-
260
-
261
- Log.v("Maでtrueだったため、if文に入る :",doge);
262
-
263
- String sqlup="update "+table1+" set doge='false'";
264
-
265
- Cursor cup=db.rawQuery(sqlup,null);
266
-
267
-
268
-
269
- //trueってことは、24時間たったってことだからbzを0にして体力回復させる
270
-
271
- bz=0;
272
-
273
-
274
-
275
- String zzz=String.valueOf(bz);
276
-
277
- Log.v("bzは0になるはずなのに",zzz);
278
-
279
-
280
-
281
- }
282
-
283
- ca.close();
284
-
285
- // cd.close();
286
484
 
287
485
 
288
486
 
289
487
  }
290
488
 
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
- private static final String TAG = MainActivity.class.getSimpleName();
300
-
301
-
302
-
303
- //Resetのコード
304
-
305
- public void addReset(int resetHour, int resetMinute) {
306
-
307
-
308
-
309
- // Reset(リセット)を設定する
310
-
311
- PendingIntent mResetSender = this.getPendingIntent();
312
-
313
-
314
-
315
- // リセットするメソッドを呼ぶ時間の設定
316
-
317
- java.util.Calendar cal = java.util.Calendar.getInstance();
318
-
319
- cal.setTimeInMillis(System.currentTimeMillis());
320
-
321
- // 設定した時刻をカレンダーに設定
322
-
323
- cal.set(cal.HOUR_OF_DAY, resetHour);
324
-
325
- cal.set(cal.MINUTE, resetMinute);
326
-
327
- cal.set(cal.SECOND, 0);
328
-
329
- cal.set(cal.MILLISECOND, 0);
330
-
331
-
332
-
333
- Toast.makeText(this, String.format("%d時%d分にtoast表示のメソッドを呼びます", resetHour, resetMinute), Toast.LENGTH_LONG).show();
334
-
335
-
336
-
337
- // AlramManager取得
338
-
339
- AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
340
-
341
- // AlarmManagerにPendingIntentを登録
342
-
343
- am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), mResetSender);
344
-
345
-
346
-
347
-
348
-
349
- Log.v(TAG, cal.getTimeInMillis() + "ms");
350
-
351
- Log.v(TAG, "2:30に表示するメソッドを呼ぶ、セット完了");
489
+ }
490
+
491
+ ```
492
+
493
+ //Databaseset
494
+
495
+ ```java
496
+
497
+
498
+
499
+ public class Databaseset extends SQLiteOpenHelper {
500
+
501
+
502
+
503
+
504
+
505
+ public static final String DB_NAME="bodyhp.db";
506
+
507
+ public static final int DB_VERSION=2;
508
+
509
+
510
+
511
+ public static final String CREATE_TABLE=
512
+
513
+ "create table " + Usersdata.Users.TABLE_NAME + "(" +
514
+
515
+ Usersdata.Users._ID + " integer primary key autoincrement, " +
516
+
517
+ Usersdata.Users.COL_HP + " text, " +
518
+
519
+ Usersdata.Users.COL_DATA + " text)";
520
+
521
+
522
+
523
+ public static final String CREATE_TABLE1=
524
+
525
+ "create table "+Usersdata.Users.TABLE_NAME1+"("+
526
+
527
+ Usersdata.Users.DOGE+" text )";
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
352
536
 
353
537
  }
354
538
 
355
- private PendingIntent getPendingIntent() {
539
+
356
-
357
- Intent intent = new Intent(this, MyResetService.class);
540
+
358
-
359
-
360
-
361
- //このintentにクラス変数の値をsetし、Serviceでデータベースにセットする。
541
+
362
-
363
-
364
-
365
- String a=String.valueOf(j);
366
-
367
-
368
-
369
- Log.v("xxxxxxxxxx",a);
370
-
371
-
372
-
373
- PendingIntent pendingIntent = PendingIntent.getService(this, PendingIntent.FLAG_ONE_SHOT, intent, PendingIntent.FLAG_UPDATE_CURRENT);
374
-
375
- return pendingIntent;
376
-
377
-
378
-
379
- }
380
-
381
-
382
-
383
- }
384
542
 
385
543
  ```
386
-
387
- //MyResetService
388
-
389
- ```java
390
-
391
- public class MyResetService extends Service {
392
-
393
-
394
-
395
-
396
-
397
- private static final String TAG = MyResetService.class.getSimpleName();
398
-
399
-
400
-
401
-
402
-
403
- @Override
404
-
405
- public void onCreate() {
406
-
407
- Thread thr = new Thread(null, mTask, "MyResetServiceThread");
408
-
409
- thr.start();
410
-
411
- Log.v(TAG, "スレッド開始");
412
-
413
- }
414
-
415
-
416
-
417
-
418
-
419
- // アラーム用サービス
420
-
421
- Runnable mTask = new Runnable() {
422
-
423
- public void run() {
424
-
425
-
426
-
427
-
428
-
429
- Log.v(TAG, "あああああああああああ:これがLogに表示されれば HPの現時点での残りはもう関係ない。");
430
-
431
-
432
-
433
- SQLiteDatabase db = null;
434
-
435
- Databaseset databaseset = new Databaseset(MyResetService.this);
436
-
437
- db = databaseset.getWritableDatabase();
438
-
439
-
440
-
441
- String table1 = Usersdata.Users.TABLE_NAME1;
442
-
443
- String sql = "select * from " + table1;
444
-
445
- Cursor cz = db.rawQuery(sql, null);
446
-
447
-
448
-
449
-
450
-
451
- //trueにしとく
452
-
453
- String doge = "true";
454
-
455
-
456
-
457
- ////////////ここは入れてない
458
-
459
- boolean isEof = cz.moveToFirst();
460
-
461
- // データを取得していく
462
-
463
- while(isEof) {
464
-
465
- doge = cz.getString(cz.getColumnIndex(Usersdata.Users.DOGE));
466
-
467
- Log.v("おおおおおい",doge);
468
-
469
- //moveToFirstがスルーされてる
470
-
471
- }
472
-
473
- if (doge == "false") {
474
-
475
- //treuになってたら、Serviceでtrueにしたってこと
476
-
477
-
478
-
479
-
480
-
481
- String sqlup = "update " + table1 + " set doge='true'";
482
-
483
- Cursor cup = db.rawQuery(sqlup, null);
484
-
485
-
486
-
487
- Log.v("Serviceでfalseでifへ :", doge);
488
-
489
-
490
-
491
- }
492
-
493
-
494
-
495
- // 役目を終えたサービスを止める
496
-
497
- //サービスを停止
498
-
499
- MyResetService.this.stopSelf();
500
-
501
- Log.v(TAG, "サービス停止");
502
-
503
-
504
-
505
- }
506
-
507
-
508
-
509
- };
510
-
511
- }
512
-
513
- ```
514
-
515
- //Usersdata
516
-
517
- ```java
518
-
519
- package com.example.android.sample.physicalstrength;
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
- import android.provider.BaseColumns;
528
-
529
-
530
-
531
- /**
532
-
533
- * Created by endoutaichi on 2017/04/22.
534
-
535
- */
536
-
537
-
538
-
539
- public class Usersdata {
540
-
541
-
542
-
543
- public Usersdata(){}
544
-
545
-
546
-
547
- public static abstract class Users implements BaseColumns {
548
-
549
-
550
-
551
-
552
-
553
-
554
-
555
- public static final String _ID="id";
556
-
557
- public static final String TABLE_NAME="body";
558
-
559
- public static final String TABLE_NAME1="new1";
560
-
561
- public static final String COL_HP="hp";
562
-
563
- public static final String COL_DATA="data";
564
-
565
-
566
-
567
- public static final String DOGE="doge";
568
-
569
-
570
-
571
-
572
-
573
- }
574
-
575
- }
576
-
577
- ```
578
-
579
- //Databaseset
580
-
581
- ```java
582
-
583
-
584
-
585
- public class Databaseset extends SQLiteOpenHelper {
586
-
587
-
588
-
589
-
590
-
591
- public static final String DB_NAME="bodyhp.db";
592
-
593
- public static final int DB_VERSION=2;
594
-
595
-
596
-
597
- public static final String CREATE_TABLE=
598
-
599
- "create table " + Usersdata.Users.TABLE_NAME + "(" +
600
-
601
- Usersdata.Users._ID + " integer primary key autoincrement, " +
602
-
603
- Usersdata.Users.COL_HP + " text, " +
604
-
605
- Usersdata.Users.COL_DATA + " text)";
606
-
607
-
608
-
609
- public static final String CREATE_TABLE1=
610
-
611
- "create table "+Usersdata.Users.TABLE_NAME1+"("+
612
-
613
- Usersdata.Users.DOGE+" text )";
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
- }
624
-
625
-
626
-
627
-
628
-
629
- ```

1

誤字

2017/04/24 01:49

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -16,9 +16,9 @@
16
16
 
17
17
 
18
18
 
19
- MainActivityで、if文でデータベースから取得した値がtrueであれば、今日の通算残りHPを0とリセットし、trueをfalseにかえ、24時になると、AlarmManagerの起動によって移動先のServiceで、trueにアップデートする。
19
+ MainActivityで、if文でデータベースから取得した値がtrueであれば、今日の残りHPを100とリセットし、データベースのtrueをfalseにupdateし、24時になると、AlarmManagerの起動によって移動先のServiceで、trueにアップデートする。
20
-
20
+
21
- そうすることで、24時になった時、AlarmManager、Serviceと行き来する時だけ、MainActivityのボタンのonClickListenerの中のi++によって大きくなった本日の残り体力:iを初期化することができるとう仕組みです。
21
+ そうすることで、onStart()のなかでありながら、24時になった時、AlarmManagerによって、Serviceと行き来する時だけ、MainActivityのbuttonのonClickListenerの中の100-(i++)によって小さくなった残り体力:iを100に初期化するということを実現したいです。
22
22
 
23
23
 
24
24