質問編集履歴

3

2019/06/30 16:37

投稿

bake
bake

スコア13

test CHANGED
File without changes
test CHANGED
@@ -16,222 +16,222 @@
16
16
 
17
17
  //タイマーに時間をセットするの//エラーのコードにfinalを宣言する必要が
18
18
 
19
- あるとえらーが出ます
19
+ あるとえらーが出ます
20
-
20
+
21
+
22
+
21
- ```
23
+ ```
24
+
22
-
25
+ ```java
26
+
23
-
27
+ public class TimerActivity extends AppCompatActivity {
28
+
29
+
30
+
24
-
31
+ private TextView timerText;
32
+
33
+ private EditText edit;
34
+
35
+ private SharedPreferences data;
36
+
37
+
38
+
39
+
40
+
41
+ // 表示形式を設定
42
+
43
+ private SimpleDateFormat dataFormat = new SimpleDateFormat("mm:ss.SSS");
44
+
45
+
46
+
47
+ @Override
48
+
49
+ protected void onCreate(Bundle savedInstanceState) {
50
+
51
+ super.onCreate(savedInstanceState);
52
+
53
+ setContentView(R.layout.my_fragment);
54
+
55
+
56
+
57
+ edit= (EditText)findViewById(R.id.time);
58
+
59
+
60
+
61
+
62
+
63
+ //タイマーの初期時間の設定 msec
64
+
65
+ final long countNumber = 60000;
66
+
67
+
68
+
69
+
70
+
71
+ // インターバル msec
72
+
73
+ long interval = 100;
74
+
75
+
76
+
77
+ // レイアウトと関連
78
+
79
+ Button startButton = findViewById(R.id.start_button);
80
+
81
+ Button stopButton = findViewById(R.id.stop_button);
82
+
83
+ Button resetButton = findViewById(R.id.reset_button);
84
+
85
+ Button setButton = findViewById(R.id.set_button);
86
+
87
+ Button button1 = (Button) findViewById(R.id.main_button);
88
+
89
+
90
+
91
+ //テキストに初期時間の設定msec
92
+
93
+ timerText = findViewById(R.id.timer);
94
+
95
+ timerText.setText(dataFormat.format(180000));
96
+
97
+
98
+
99
+ // インスタンス生成
100
+
101
+ // CountDownTimer(long millisInFuture, long countDownInterval)
102
+
103
+ final CountDown countDown = new CountDown(countNumber, interval);
104
+
105
+
106
+
107
+ //タイマー開始
108
+
109
+ startButton.setOnClickListener(new View.OnClickListener() {
110
+
111
+ @Override
112
+
113
+ public void onClick(View v) {
114
+
115
+
116
+
117
+
118
+
119
+ countDown.start();
120
+
121
+ }
122
+
25
- ###
123
+ });
124
+
125
+
126
+
127
+ //タイマー中止
128
+
129
+ stopButton.setOnClickListener(new View.OnClickListener(){
130
+
131
+ @Override
132
+
133
+ public void onClick(View v) {
134
+
135
+ // 中止
136
+
137
+ countDown.cancel();
138
+
139
+ }
140
+
141
+ });
142
+
143
+
144
+
145
+ //タイマーリセット
146
+
147
+ resetButton.setOnClickListener(new View.OnClickListener(){
148
+
149
+ @Override
150
+
151
+ public void onClick(View v) {
152
+
153
+ // リセット
154
+
155
+ timerText.setText(dataFormat.format(180000));
156
+
157
+ }
158
+
159
+ });
160
+
161
+     //タイマーに時間をセットする。
162
+
163
+ setButton.setOnClickListener(new View.OnClickListener() {
164
+
165
+ @Override
166
+
167
+ public void onClick(View v) {
168
+
169
+ //時間をセットする。
170
+
171
+ String time = edit.getText().toString();
172
+
173
+ timerText.setText(time);
174
+
175
+ long time1 = Long.valueOf(time);
176
+
177
+   //エラー→       countNumber = timesec1
178
+
179
+
180
+
181
+ SharedPreferences data = getSharedPreferences("save", Context.MODE_PRIVATE);
182
+
183
+ SharedPreferences.Editor editor = data.edit();
184
+
185
+ editor.putLong( "save", timesec1 );
186
+
187
+ editor.commit();
188
+
189
+
190
+
191
+ /CountDownTimerクラス
192
+
193
+ // class CountDown extends CountDownTimer {
194
+
195
+ //
196
+
197
+ // CountDown(long millisInFuture, long countDownInterval) {
198
+
199
+ // super(millisInFuture, countDownInterval);
200
+
201
+ // }
202
+
203
+ // //タイマー終了後
204
+
205
+ // @Override
206
+
207
+ // public void onFinish() {
208
+
209
+ // // 完了
210
+
211
+ // timerText.setText(dataFormat.format(0));
212
+
213
+ // }
214
+
215
+ //
216
+
217
+ // // インターバルで呼ばれる
218
+
219
+ // @Override
220
+
221
+ // public void onTick(long millisInFuture) {
222
+
223
+ // timerText.setText(dataFormat.format(millisInFuture));
224
+
225
+ //
226
+
227
+ // }
228
+
229
+ // }
230
+
231
+ ```
26
232
 
27
233
  <code>
28
234
 
29
- public class TimerActivity extends AppCompatActivity {
30
-
31
-
32
-
33
- private TextView timerText;
34
-
35
- private EditText edit;
36
-
37
- private SharedPreferences data;
38
-
39
-
40
-
41
-
42
-
43
- // 表示形式を設定
44
-
45
- private SimpleDateFormat dataFormat = new SimpleDateFormat("mm:ss.SSS");
46
-
47
-
48
-
49
- @Override
50
-
51
- protected void onCreate(Bundle savedInstanceState) {
52
-
53
- super.onCreate(savedInstanceState);
54
-
55
- setContentView(R.layout.my_fragment);
56
-
57
-
58
-
59
- edit= (EditText)findViewById(R.id.time);
60
-
61
-
62
-
63
-
64
-
65
- //タイマーの初期時間の設定 msec
66
-
67
- final long countNumber = 60000;
68
-
69
-
70
-
71
-
72
-
73
- // インターバル msec
74
-
75
- long interval = 100;
76
-
77
-
78
-
79
- // レイアウトと関連
80
-
81
- Button startButton = findViewById(R.id.start_button);
82
-
83
- Button stopButton = findViewById(R.id.stop_button);
84
-
85
- Button resetButton = findViewById(R.id.reset_button);
86
-
87
- Button setButton = findViewById(R.id.set_button);
88
-
89
- Button button1 = (Button) findViewById(R.id.main_button);
90
-
91
-
92
-
93
- //テキストに初期時間の設定msec
94
-
95
- timerText = findViewById(R.id.timer);
96
-
97
- timerText.setText(dataFormat.format(180000));
98
-
99
-
100
-
101
- // インスタンス生成
102
-
103
- // CountDownTimer(long millisInFuture, long countDownInterval)
104
-
105
- final CountDown countDown = new CountDown(countNumber, interval);
106
-
107
-
108
-
109
- //タイマー開始
110
-
111
- startButton.setOnClickListener(new View.OnClickListener() {
112
-
113
- @Override
114
-
115
- public void onClick(View v) {
116
-
117
-
118
-
119
-
120
-
121
- countDown.start();
122
-
123
- }
124
-
125
- });
126
-
127
-
128
-
129
- //タイマー中止
130
-
131
- stopButton.setOnClickListener(new View.OnClickListener(){
132
-
133
- @Override
134
-
135
- public void onClick(View v) {
136
-
137
- // 中止
138
-
139
- countDown.cancel();
140
-
141
- }
142
-
143
- });
144
-
145
-
146
-
147
- //タイマーリセット
148
-
149
- resetButton.setOnClickListener(new View.OnClickListener(){
150
-
151
- @Override
152
-
153
- public void onClick(View v) {
154
-
155
- // リセット
156
-
157
- timerText.setText(dataFormat.format(180000));
158
-
159
- }
160
-
161
- });
162
-
163
-     //タイマーに時間をセットする。
164
-
165
- setButton.setOnClickListener(new View.OnClickListener() {
166
-
167
- @Override
168
-
169
- public void onClick(View v) {
170
-
171
- //時間をセットする。
172
-
173
- String time = edit.getText().toString();
174
-
175
- timerText.setText(time);
176
-
177
- long time1 = Long.valueOf(time);
178
-
179
-   //エラー→       countNumber = timesec1
180
-
181
-
182
-
183
- SharedPreferences data = getSharedPreferences("save", Context.MODE_PRIVATE);
184
-
185
- SharedPreferences.Editor editor = data.edit();
186
-
187
- editor.putLong( "save", timesec1 );
188
-
189
- editor.commit();
190
-
191
-
192
-
193
- /CountDownTimerクラス
194
-
195
- // class CountDown extends CountDownTimer {
196
-
197
- //
198
-
199
- // CountDown(long millisInFuture, long countDownInterval) {
200
-
201
- // super(millisInFuture, countDownInterval);
202
-
203
- // }
204
-
205
- // //タイマー終了後
206
-
207
- // @Override
208
-
209
- // public void onFinish() {
210
-
211
- // // 完了
212
-
213
- // timerText.setText(dataFormat.format(0));
214
-
215
- // }
216
-
217
- //
218
-
219
- // // インターバルで呼ばれる
220
-
221
- // @Override
222
-
223
- // public void onTick(long millisInFuture) {
224
-
225
- // timerText.setText(dataFormat.format(millisInFuture));
226
-
227
- //
228
-
229
- // }
230
-
231
- // }
232
-
233
- <code>
234
-
235
235
 
236
236
 
237
237
 

2

2019/06/30 16:37

投稿

bake
bake

スコア13

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  ###
26
26
 
27
-
27
+ <code>
28
28
 
29
29
  public class TimerActivity extends AppCompatActivity {
30
30
 
@@ -230,7 +230,7 @@
230
230
 
231
231
  // }
232
232
 
233
-
233
+ <code>
234
234
 
235
235
 
236
236
 
@@ -238,7 +238,7 @@
238
238
 
239
239
  ```ここに言語名を入力
240
240
 
241
- androidjava
241
+ java
242
242
 
243
243
  ```
244
244
 

1

説明追加

2019/06/30 16:27

投稿

bake
bake

スコア13

test CHANGED
File without changes
test CHANGED
@@ -246,7 +246,7 @@
246
246
 
247
247
  ### 試したこと
248
248
 
249
-
249
+ finalを書いてみましたが駄目でした。
250
250
 
251
251
  Sharedpreferenceを使って時間を保存しようとしてみましたが反映されませんでした。
252
252