質問編集履歴

6

2019/06/10 23:16

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -23,393 +23,3 @@
23
23
  #現在解決できていない問題
24
24
 
25
25
  ラップタイムを表示する
26
-
27
-
28
-
29
- #記入したコード(成功した部分まで)
30
-
31
-
32
-
33
- ```java
34
-
35
-
36
-
37
- import android.content.Intent;
38
-
39
- import android.os.Bundle;
40
-
41
- import android.os.Handler;
42
-
43
- import android.support.v7.app.AppCompatActivity;
44
-
45
- import android.view.View;
46
-
47
- import android.widget.ArrayAdapter;
48
-
49
- import android.widget.Button;
50
-
51
- import android.widget.ListView;
52
-
53
- import android.widget.TextView;
54
-
55
-
56
-
57
- import java.util.ArrayList;
58
-
59
- import java.util.HashMap;
60
-
61
- import java.util.Locale;
62
-
63
- import java.util.Map;
64
-
65
- import java.util.Timer;
66
-
67
- import java.util.TimerTask;
68
-
69
-
70
-
71
- public class StopWatch extends AppCompatActivity {
72
-
73
-
74
-
75
- Timer timer;
76
-
77
- CountUpTimerTask timerTask;
78
-
79
- Handler handler = new Handler();
80
-
81
-
82
-
83
- TextView timerText,sub,num;
84
-
85
- long count, delay, period;
86
-
87
- String zero;
88
-
89
- ListView listView;
90
-
91
- Button rapButton,startButton,stopButton,interruptButton,restartButton,resetButton;
92
-
93
- int i=0;
94
-
95
-
96
-
97
- // boolean isPause=false;
98
-
99
- long mm,ss,ms;
100
-
101
- long mm2=0;
102
-
103
- long ss2=0;
104
-
105
- long mm3=0;
106
-
107
- long ss3=0;
108
-
109
-
110
-
111
-
112
-
113
- @Override
114
-
115
- protected void onCreate(Bundle savedInstanceState) {
116
-
117
- super.onCreate(savedInstanceState);
118
-
119
- setContentView(R.layout.activity_stop_watch);
120
-
121
-
122
-
123
- // Intent を取得する
124
-
125
- Intent intent = getIntent();
126
-
127
-
128
-
129
- delay = 0;
130
-
131
- period = 100;
132
-
133
- // "00:00.0"
134
-
135
- zero = getString(R.string.zero);
136
-
137
-
138
-
139
- timerText = findViewById(R.id.timer);
140
-
141
- timerText.setText(zero);
142
-
143
-
144
-
145
-
146
-
147
- // タイマー開始
148
-
149
- startButton = findViewById(R.id.start_button);
150
-
151
- startButton.setOnClickListener(new View.OnClickListener() {
152
-
153
- @Override
154
-
155
- public void onClick(View v) {
156
-
157
-
158
-
159
- // タイマーが走っている最中にボタンをタップされたケース
160
-
161
- if(null != timer){
162
-
163
- timer.cancel();
164
-
165
- timer = null;
166
-
167
- }
168
-
169
-
170
-
171
- // Timer インスタンスを生成
172
-
173
- timer = new Timer();
174
-
175
-
176
-
177
- // TimerTask インスタンスを生成
178
-
179
- timerTask = new CountUpTimerTask();
180
-
181
-
182
-
183
- // スケジュールを設定 100msec
184
-
185
- // public void schedule (TimerTask task, long delay, long period)
186
-
187
- timer.schedule(timerTask, delay, period);
188
-
189
-
190
-
191
- // カウンター
192
-
193
- count = 0;
194
-
195
- timerText.setText(zero);
196
-
197
-
198
-
199
- }
200
-
201
- });
202
-
203
-
204
-
205
- // タイマー終了
206
-
207
- stopButton = findViewById(R.id.stop_button);
208
-
209
- stopButton.setOnClickListener(new View.OnClickListener(){
210
-
211
- @Override
212
-
213
- public void onClick(View v) {
214
-
215
- // Cancel
216
-
217
- timer.cancel();
218
-
219
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
220
-
221
-
222
-
223
- }
224
-
225
- });
226
-
227
-
228
-
229
- interruptButton = findViewById(R.id.interrupt_button);
230
-
231
- interruptButton.setOnClickListener(new View.OnClickListener(){
232
-
233
- @Override
234
-
235
- public void onClick(View v){
236
-
237
- // Cancel
238
-
239
- timer.cancel();
240
-
241
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
242
-
243
- mm2=mm;
244
-
245
- ss2=ss;
246
-
247
-
248
-
249
- // isPause=true;
250
-
251
-
252
-
253
- }
254
-
255
- });
256
-
257
- restartButton = findViewById(R.id.restart_button);
258
-
259
- restartButton.setOnClickListener(new View.OnClickListener(){
260
-
261
- @Override
262
-
263
- public void onClick(View v) {
264
-
265
-
266
-
267
- //再びとめた時間から開始する処理
268
-
269
- timer = new Timer();
270
-
271
- timerTask = new CountUpTimerTask();
272
-
273
- timer.schedule(timerTask, delay, period);
274
-
275
- count = 0;
276
-
277
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
278
-
279
-
280
-
281
- }
282
-
283
- });
284
-
285
-
286
-
287
- resetButton = findViewById(R.id.reset_button);
288
-
289
- resetButton.setOnClickListener(new View.OnClickListener(){
290
-
291
- @Override
292
-
293
- public void onClick(View v) {
294
-
295
- timer = null;
296
-
297
- mm2=0;
298
-
299
- ss2=0;
300
-
301
- mm=0;
302
-
303
- ss=0;
304
-
305
- count = 0;
306
-
307
- timerText.setText(zero);
308
-
309
- }
310
-
311
- });
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
- rapButton = (Button)findViewById(R.id.rap);
320
-
321
- rapButton.setOnClickListener(new View.OnClickListener(){
322
-
323
- @Override
324
-
325
- public void onClick(View v) {
326
-
327
-
328
-
329
- // //ボタンを押したときのタイムを表示する処理
330
-
331
- // ArrayList<String> items = new ArrayList<>();
332
-
333
- // items.add("");
334
-
335
- //
336
-
337
- // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.activity_stop_watch, items);
338
-
339
- //
340
-
341
- // // ListViewに表示
342
-
343
- // listView = (ListView)findViewById(R.id.list);
344
-
345
- // listView.setAdapter(adapter);
346
-
347
- //
348
-
349
-
350
-
351
- i++;
352
-
353
- String s = String.valueOf(i);
354
-
355
- sub = findViewById(R.id.subtext);
356
-
357
- num = findViewById(R.id.num);
358
-
359
- sub.setText(String.format(Locale.US, "%1$02d:%2$02d", mm-mm3,ss-ss3));
360
-
361
- num.setText(s+"回目");
362
-
363
- mm3=mm;
364
-
365
- ss3=ss;
366
-
367
-
368
-
369
- }
370
-
371
- });
372
-
373
-
374
-
375
-
376
-
377
- }
378
-
379
-
380
-
381
- class CountUpTimerTask extends TimerTask {
382
-
383
- @Override
384
-
385
- public void run() {
386
-
387
- // handlerを使って処理をキューイングする
388
-
389
- handler.post(new Runnable() {
390
-
391
- public void run() {
392
-
393
- count++;
394
-
395
- mm = (count*100 / 1000+mm2) / 60;
396
-
397
- ss = (count*100 / 1000+ss2) % 60;
398
-
399
- // 桁数を合わせるために02d(2桁)を設定
400
-
401
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
402
-
403
- }
404
-
405
- });
406
-
407
- }
408
-
409
- }
410
-
411
-
412
-
413
- }
414
-
415
- ```

5

間違いの訂正

2019/06/10 23:16

投稿

poohrk
poohrk

スコア12

test CHANGED
@@ -1 +1 @@
1
- 中断、再開の機能をつけたストップウォッチ[android studio]
1
+ ストップウォッチ[android studio]
test CHANGED
File without changes

4

コードの訂正

2018/10/26 05:24

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,7 @@
1
+ コードの部分編集させていただきました。
2
+
3
+
4
+
1
5
  #実現したいこと
2
6
 
3
7
 
@@ -30,6 +34,8 @@
30
34
 
31
35
 
32
36
 
37
+ import android.content.Intent;
38
+
33
39
  import android.os.Bundle;
34
40
 
35
41
  import android.os.Handler;
@@ -38,18 +44,24 @@
38
44
 
39
45
  import android.view.View;
40
46
 
47
+ import android.widget.ArrayAdapter;
48
+
41
49
  import android.widget.Button;
42
50
 
43
- import android.widget.ScrollView;
51
+ import android.widget.ListView;
44
52
 
45
53
  import android.widget.TextView;
46
54
 
55
+
56
+
47
- import android.widget.Toast;
57
+ import java.util.ArrayList;
58
+
48
-
59
+ import java.util.HashMap;
49
-
50
60
 
51
61
  import java.util.Locale;
52
62
 
63
+ import java.util.Map;
64
+
53
65
  import java.util.Timer;
54
66
 
55
67
  import java.util.TimerTask;
@@ -68,13 +80,21 @@
68
80
 
69
81
 
70
82
 
71
- TextView timerText;
83
+ TextView timerText,sub,num;
72
84
 
73
85
  long count, delay, period;
74
86
 
75
87
  String zero;
76
88
 
89
+ ListView listView;
90
+
91
+ Button rapButton,startButton,stopButton,interruptButton,restartButton,resetButton;
92
+
93
+ int i=0;
94
+
95
+
96
+
77
- // boolean isPause=false;
97
+ // boolean isPause=false;
78
98
 
79
99
  long mm,ss,ms;
80
100
 
@@ -82,7 +102,9 @@
82
102
 
83
103
  long ss2=0;
84
104
 
85
- long ms2=0;
105
+ long mm3=0;
106
+
107
+ long ss3=0;
86
108
 
87
109
 
88
110
 
@@ -98,6 +120,12 @@
98
120
 
99
121
 
100
122
 
123
+ // Intent を取得する
124
+
125
+ Intent intent = getIntent();
126
+
127
+
128
+
101
129
  delay = 0;
102
130
 
103
131
  period = 100;
@@ -114,9 +142,11 @@
114
142
 
115
143
 
116
144
 
145
+
146
+
117
147
  // タイマー開始
118
148
 
119
- Button startButton = findViewById(R.id.start_button);
149
+ startButton = findViewById(R.id.start_button);
120
150
 
121
151
  startButton.setOnClickListener(new View.OnClickListener() {
122
152
 
@@ -174,7 +204,7 @@
174
204
 
175
205
  // タイマー終了
176
206
 
177
- Button stopButton = findViewById(R.id.stop_button);
207
+ stopButton = findViewById(R.id.stop_button);
178
208
 
179
209
  stopButton.setOnClickListener(new View.OnClickListener(){
180
210
 
@@ -196,7 +226,7 @@
196
226
 
197
227
 
198
228
 
199
- Button interruptButton = findViewById(R.id.interrupt_button);
229
+ interruptButton = findViewById(R.id.interrupt_button);
200
230
 
201
231
  interruptButton.setOnClickListener(new View.OnClickListener(){
202
232
 
@@ -224,7 +254,7 @@
224
254
 
225
255
  });
226
256
 
227
- Button restartButton = findViewById(R.id.restart_button);
257
+ restartButton = findViewById(R.id.restart_button);
228
258
 
229
259
  restartButton.setOnClickListener(new View.OnClickListener(){
230
260
 
@@ -254,7 +284,7 @@
254
284
 
255
285
 
256
286
 
257
- Button resetButton = findViewById(R.id.reset_button);
287
+ resetButton = findViewById(R.id.reset_button);
258
288
 
259
289
  resetButton.setOnClickListener(new View.OnClickListener(){
260
290
 
@@ -282,7 +312,11 @@
282
312
 
283
313
 
284
314
 
315
+
316
+
317
+
318
+
285
- Button rapButton = findViewById(R.id.rap);
319
+ rapButton = (Button)findViewById(R.id.rap);
286
320
 
287
321
  rapButton.setOnClickListener(new View.OnClickListener(){
288
322
 
@@ -290,15 +324,55 @@
290
324
 
291
325
  public void onClick(View v) {
292
326
 
327
+
328
+
293
- //ボタンを押したときのタイムを表示する処理
329
+ // //ボタンを押したときのタイムを表示する処理
330
+
294
-
331
+ // ArrayList<String> items = new ArrayList<>();
332
+
295
-
333
+ // items.add("");
334
+
296
-
335
+ //
336
+
297
-
337
+ // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.activity_stop_watch, items);
338
+
298
-
339
+ //
340
+
341
+ // // ListViewに表示
342
+
343
+ // listView = (ListView)findViewById(R.id.list);
344
+
345
+ // listView.setAdapter(adapter);
346
+
347
+ //
348
+
349
+
350
+
351
+ i++;
352
+
353
+ String s = String.valueOf(i);
354
+
355
+ sub = findViewById(R.id.subtext);
356
+
357
+ num = findViewById(R.id.num);
358
+
359
+ sub.setText(String.format(Locale.US, "%1$02d:%2$02d", mm-mm3,ss-ss3));
360
+
361
+ num.setText(s+"回目");
362
+
363
+ mm3=mm;
364
+
365
+ ss3=ss;
366
+
367
+
368
+
299
- }
369
+ }
300
-
370
+
301
- });
371
+ });
372
+
373
+
374
+
375
+
302
376
 
303
377
  }
304
378
 

3

誤字の修正

2018/10/17 05:28

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- #解決できない問題
19
+ #現在解決できていない問題
20
20
 
21
21
  ラップタイムを表示する
22
22
 

2

2つの問題のうち解決した問題の消去

2018/10/11 07:55

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -4,30 +4,24 @@
4
4
 
5
5
  androidでラップタイム、中断、再開の機能をつけたストップウォッチを作ろうと思っています。
6
6
 
7
+
8
+
9
+ <未解決の問題>
10
+
7
- 中断処理や時間の表示まではできたのでがその後がうまくできません。
11
+ 記録した内容を示すtextを増していく方法やrapごとの時間を記方法
12
+
13
+ <解決済みの内容>
14
+
15
+ 再開の方法
8
16
 
9
17
 
10
18
 
11
19
  #解決できない問題
12
20
 
13
-
14
-
15
- ストップウォッチを再開させる(時間を正確に表示)
16
-
17
21
  ラップタイムを表示する
18
22
 
19
23
 
20
24
 
21
- #行ったこと
22
-
23
-
24
-
25
- 中断後もともとの時間を他の変数にいれ再スタートし表示は中断前の時間と計測中の時間をプラスしようと思いましたが再開ボタンを押すとエラーになってしまいました。
26
-
27
-
28
-
29
-
30
-
31
25
  #記入したコード(成功した部分まで)
32
26
 
33
27
 
@@ -84,11 +78,11 @@
84
78
 
85
79
  long mm,ss,ms;
86
80
 
87
- // long mm2=0;
81
+ long mm2=0;
88
-
82
+
89
- // long ss2=0;
83
+ long ss2=0;
90
-
84
+
91
- // long ms2=0;
85
+ long ms2=0;
92
86
 
93
87
 
94
88
 
@@ -192,7 +186,7 @@
192
186
 
193
187
  timer.cancel();
194
188
 
195
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d.%3$01d", mm, ss, ms));
189
+ timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
196
190
 
197
191
 
198
192
 
@@ -214,20 +208,18 @@
214
208
 
215
209
  timer.cancel();
216
210
 
217
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d.%3$01d", mm, ss, ms));
211
+ timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
218
-
212
+
219
- // mm2=mm;
213
+ mm2=mm;
220
-
214
+
221
- // ss2=ss;
215
+ ss2=ss;
222
-
223
- // ms2=ms;
216
+
217
+
224
218
 
225
219
  // isPause=true;
226
220
 
227
221
 
228
222
 
229
-
230
-
231
223
  }
232
224
 
233
225
  });
@@ -244,7 +236,15 @@
244
236
 
245
237
  //再びとめた時間から開始する処理
246
238
 
239
+ timer = new Timer();
240
+
241
+ timerTask = new CountUpTimerTask();
242
+
247
- // timer.schedule(timerTask, delay, period);
243
+ timer.schedule(timerTask, delay, period);
244
+
245
+ count = 0;
246
+
247
+ timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
248
248
 
249
249
 
250
250
 
@@ -264,6 +264,16 @@
264
264
 
265
265
  timer = null;
266
266
 
267
+ mm2=0;
268
+
269
+ ss2=0;
270
+
271
+ mm=0;
272
+
273
+ ss=0;
274
+
275
+ count = 0;
276
+
267
277
  timerText.setText(zero);
268
278
 
269
279
  }
@@ -282,7 +292,7 @@
282
292
 
283
293
  //ボタンを押したときのタイムを表示する処理
284
294
 
285
-
295
+
286
296
 
287
297
 
288
298
 
@@ -308,15 +318,13 @@
308
318
 
309
319
  count++;
310
320
 
311
- mm = count*100 / 1000 / 60;
321
+ mm = (count*100 / 1000+mm2) / 60;
312
-
322
+
313
- ss = count*100 / 1000 % 60;
323
+ ss = (count*100 / 1000+ss2) % 60;
314
-
315
- ms = (count*100 - ss * 1000 - mm * 1000 * 60)/100;
316
324
 
317
325
  // 桁数を合わせるために02d(2桁)を設定
318
326
 
319
- timerText.setText(String.format(Locale.US, "%1$02d:%2$02d.%3$01d", mm, ss, ms));
327
+ timerText.setText(String.format(Locale.US, "%1$02d:%2$02d", mm, ss));
320
328
 
321
329
  }
322
330
 

1

2018/10/11 07:53

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -34,8 +34,6 @@
34
34
 
35
35
  ```java
36
36
 
37
- package com.example.mori.stopwatch;
38
-
39
37
 
40
38
 
41
39
  import android.os.Bundle;