質問編集履歴
6
SubActivity.ktの最新版とご回答を受けての修正とエラーの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,468 +26,442 @@
|
|
26
26
|
|
27
27
|
### ご回答を受けての修正とエラー
|
28
28
|
|
29
|
+
スピナーで選択した項目のデータが移行先のページで表示されません
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
MainActivity.kt
|
34
|
+
|
35
|
+
```kotlin
|
36
|
+
|
37
|
+
package com.example.sample
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
import androidx.appcompat.app.AppCompatActivity
|
42
|
+
|
43
|
+
import android.os.Bundle
|
44
|
+
|
29
|
-
|
45
|
+
import android.app.Activity
|
46
|
+
|
47
|
+
import android.content.Intent
|
48
|
+
|
49
|
+
import android.util.Log
|
50
|
+
|
51
|
+
import android.view.View
|
52
|
+
|
53
|
+
import android.widget.AdapterView
|
54
|
+
|
55
|
+
import android.widget.Spinner
|
56
|
+
|
57
|
+
import android.widget.ArrayAdapter
|
58
|
+
|
59
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
60
|
+
|
61
|
+
import android.widget.AdapterView.OnItemSelectedListener
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
class MainActivity : AppCompatActivity() {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
companion object {
|
70
|
+
|
71
|
+
const val EXTRA_MESSAGE = "com.example.kotlinactivitydatatrans.MESSAGE"
|
72
|
+
|
73
|
+
const val EXTRA_SPINNER_RESULT = "com.example.kotlinactivitydatatrans.SPINNER_RESULT"
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
//フォームからのデータ
|
80
|
+
|
81
|
+
private val RESULT_SUBACTIVITY = 1000
|
82
|
+
|
83
|
+
// スピナーの選択肢
|
84
|
+
|
85
|
+
private val spinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
86
|
+
|
87
|
+
var setectedItem: String ="Spinner"
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
92
|
+
|
93
|
+
super.onCreate(savedInstanceState)
|
94
|
+
|
95
|
+
setContentView(R.layout.activity_main)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
val spinner = findViewById<Spinner>(R.id.spinner)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
// ArrayAdapter
|
104
|
+
|
105
|
+
val adapter = ArrayAdapter(applicationContext,
|
106
|
+
|
107
|
+
android.R.layout.simple_spinner_item, spinnerItems)
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
// spinner に adapter をセット
|
116
|
+
|
117
|
+
// Kotlin Android Extensions
|
118
|
+
|
119
|
+
spinner.adapter = adapter
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
// リスナーを登録
|
124
|
+
|
125
|
+
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
126
|
+
|
127
|
+
// アイテムが選択された時
|
128
|
+
|
129
|
+
override fun onItemSelected(parent: AdapterView<*>?,
|
130
|
+
|
131
|
+
view: View?, position: Int, id: Long) {
|
132
|
+
|
133
|
+
val spinnerParent = parent as Spinner
|
134
|
+
|
135
|
+
val item = spinnerParent.selectedItem as String
|
136
|
+
|
137
|
+
// Kotlin Android Extensions
|
138
|
+
|
139
|
+
setectedItem = item
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
// アイテムが選択されなかった
|
146
|
+
|
147
|
+
override fun onNothingSelected(parent: AdapterView<*>?) {
|
148
|
+
|
149
|
+
//
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//ボタンが押されたらデータをsubページに移動する
|
158
|
+
|
159
|
+
button.setOnClickListener {
|
160
|
+
|
161
|
+
if (editText.text != null) {
|
162
|
+
|
163
|
+
val intent = Intent(applicationContext, SubActivity::class.java)
|
164
|
+
|
165
|
+
val str = editText.text.toString()
|
166
|
+
|
167
|
+
val spinner_result = setectedItem
|
168
|
+
|
169
|
+
Log.d("debug",str)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
intent.putExtra(EXTRA_MESSAGE, str)
|
174
|
+
|
175
|
+
intent.putExtra(EXTRA_SPINNER_RESULT, spinner_result)
|
176
|
+
|
177
|
+
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
178
|
+
|
179
|
+
editText.setText("")
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
30
196
|
|
31
197
|
```
|
32
198
|
|
199
|
+
|
200
|
+
|
201
|
+
SubActivity.kt
|
202
|
+
|
203
|
+
```kotlin
|
204
|
+
|
205
|
+
package com.example.sample
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
import androidx.appcompat.app.AppCompatActivity
|
210
|
+
|
211
|
+
import android.os.Bundle
|
212
|
+
|
213
|
+
import android.app.Activity
|
214
|
+
|
215
|
+
import android.content.Intent
|
216
|
+
|
217
|
+
//import kotlinx.android.synthetic.main.activity_main.*
|
218
|
+
|
219
|
+
import kotlinx.android.synthetic.main.activity_sub.*
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
class SubActivity : AppCompatActivity() {
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
228
|
+
|
229
|
+
super.onCreate(savedInstanceState)
|
230
|
+
|
231
|
+
setContentView(R.layout.activity_sub)
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
// to get message from MainActivity
|
236
|
+
|
237
|
+
val intent = getIntent()
|
238
|
+
|
239
|
+
val message = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
240
|
+
|
241
|
+
val spinner_result = intent.extras?.getString(MainActivity.EXTRA_SPINNER_RESULT)?:""
|
242
|
+
|
243
|
+
|
244
|
+
|
33
245
|
textView.text = message
|
34
246
|
|
35
247
|
//textView.text = spinner_result
|
36
248
|
|
249
|
+
|
250
|
+
|
251
|
+
//移動前のページに遷移後の画面から入力された文字列を返す
|
252
|
+
|
253
|
+
button.setOnClickListener{
|
254
|
+
|
255
|
+
val intentSub = Intent()
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
if (editText.text != null) {
|
260
|
+
|
261
|
+
val str = message + editText.text.toString()
|
262
|
+
|
263
|
+
intentSub.putExtra(MainActivity.EXTRA_MESSAGE, str)
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
editText.setText("")
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
setResult(Activity.RESULT_OK, intentSub)
|
274
|
+
|
275
|
+
finish()
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
37
285
|
```
|
38
286
|
|
39
287
|
|
40
288
|
|
289
|
+
activity_sub.xml
|
290
|
+
|
291
|
+
```xml
|
292
|
+
|
293
|
+
<?xml version="1.0" encoding="utf-8"?>
|
294
|
+
|
295
|
+
<LinearLayout
|
296
|
+
|
297
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
298
|
+
|
299
|
+
android:background="#fde"
|
300
|
+
|
301
|
+
android:orientation="vertical"
|
302
|
+
|
303
|
+
android:layout_width="match_parent"
|
304
|
+
|
305
|
+
android:layout_height="match_parent" >
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
<TextView
|
310
|
+
|
311
|
+
android:text="@string/sub"
|
312
|
+
|
313
|
+
android:textSize="24sp"
|
314
|
+
|
315
|
+
android:layout_width="match_parent"
|
316
|
+
|
317
|
+
android:layout_height="wrap_content"
|
318
|
+
|
319
|
+
android:gravity="center_horizontal"
|
320
|
+
|
321
|
+
android:layout_marginTop="40dp" />
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
<LinearLayout
|
326
|
+
|
327
|
+
android:layout_width="match_parent"
|
328
|
+
|
329
|
+
android:layout_height="wrap_content"
|
330
|
+
|
331
|
+
android:orientation="vertical">
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
<TextView
|
336
|
+
|
337
|
+
android:layout_width="wrap_content"
|
338
|
+
|
339
|
+
android:layout_height="wrap_content"
|
340
|
+
|
341
|
+
android:layout_margin="20dp"
|
342
|
+
|
343
|
+
android:text="@string/from_main"
|
344
|
+
|
345
|
+
android:textSize="24sp" />
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
<TextView
|
350
|
+
|
351
|
+
android:id="@+id/textView"
|
352
|
+
|
353
|
+
android:layout_width="220dp"
|
354
|
+
|
355
|
+
android:layout_height="wrap_content"
|
356
|
+
|
357
|
+
android:layout_margin="20dp"
|
358
|
+
|
359
|
+
android:textSize="24sp" />
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
<TextView
|
364
|
+
|
365
|
+
android:layout_width="wrap_content"
|
366
|
+
|
367
|
+
android:layout_height="wrap_content"
|
368
|
+
|
369
|
+
android:layout_margin="20dp"
|
370
|
+
|
371
|
+
android:text="@string/os_name"
|
372
|
+
|
373
|
+
android:textSize="24sp" />
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
<TextView
|
378
|
+
|
379
|
+
android:id="@+id/spinner"
|
380
|
+
|
381
|
+
android:layout_width="220dp"
|
382
|
+
|
383
|
+
android:layout_height="wrap_content"
|
384
|
+
|
385
|
+
android:layout_margin="20dp"
|
386
|
+
|
387
|
+
android:textSize="24sp" />
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
</LinearLayout>
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
<LinearLayout
|
398
|
+
|
399
|
+
android:layout_width="match_parent"
|
400
|
+
|
401
|
+
android:layout_height="wrap_content"
|
402
|
+
|
403
|
+
android:orientation="horizontal">
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
<TextView
|
408
|
+
|
409
|
+
android:layout_width="wrap_content"
|
410
|
+
|
411
|
+
android:layout_height="wrap_content"
|
412
|
+
|
413
|
+
android:layout_margin="20dp"
|
414
|
+
|
415
|
+
android:text="@string/to_main"
|
416
|
+
|
417
|
+
android:textSize="24sp" />
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
<EditText
|
422
|
+
|
423
|
+
android:id="@+id/editText"
|
424
|
+
|
425
|
+
android:layout_width="220dp"
|
426
|
+
|
427
|
+
android:layout_height="wrap_content"
|
428
|
+
|
429
|
+
android:layout_margin="20dp"
|
430
|
+
|
431
|
+
android:background="#fff"
|
432
|
+
|
433
|
+
android:hint="@string/hint2"
|
434
|
+
|
435
|
+
android:textSize="24sp" />
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
</LinearLayout>
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
<Button
|
444
|
+
|
445
|
+
android:id="@+id/button"
|
446
|
+
|
447
|
+
android:text="@string/back"
|
448
|
+
|
449
|
+
android:textSize="24sp"
|
450
|
+
|
451
|
+
android:layout_width="match_parent"
|
452
|
+
|
453
|
+
android:layout_height="wrap_content"
|
454
|
+
|
455
|
+
android:gravity="center_horizontal"
|
456
|
+
|
457
|
+
android:layout_margin="20dp" />
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
</LinearLayout>
|
462
|
+
|
41
463
|
```
|
42
464
|
|
43
|
-
Unresolved reference: textView
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
とエラーが出るようになってしまいました。
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
エミュレータで「Enter」ボタンを押すと画面遷移はしますが、フォームとプルダウンの内容は移行画面で表示されていない状態です。
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
MainActivity.kt
|
56
|
-
|
57
|
-
```kotlin
|
58
|
-
|
59
|
-
package com.example.diceroller
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
import androidx.appcompat.app.AppCompatActivity
|
64
|
-
|
65
|
-
import android.os.Bundle
|
66
|
-
|
67
|
-
import android.app.Activity
|
68
|
-
|
69
|
-
import android.content.Intent
|
70
|
-
|
71
|
-
import android.util.Log
|
72
|
-
|
73
|
-
import android.view.View
|
74
|
-
|
75
|
-
import android.widget.AdapterView
|
76
|
-
|
77
|
-
import android.widget.Spinner
|
78
|
-
|
79
|
-
import android.widget.ArrayAdapter
|
80
|
-
|
81
|
-
import kotlinx.android.synthetic.main.activity_main.*
|
82
|
-
|
83
|
-
import android.widget.AdapterView.OnItemSelectedListener
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
class MainActivity : AppCompatActivity() {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
companion object {
|
92
|
-
|
93
|
-
const val EXTRA_MESSAGE = "com.example.kotlinactivitydatatrans.MESSAGE"
|
94
|
-
|
95
|
-
const val EXTRA_SPINNER_RESULT = "com.example.kotlinactivitydatatrans.SPINNER_RESULT"
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
//フォームからのデータ
|
102
|
-
|
103
|
-
private val RESULT_SUBACTIVITY = 1000
|
104
|
-
|
105
|
-
// スピナーの選択肢
|
106
|
-
|
107
|
-
private val spinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
108
|
-
|
109
|
-
var setectedItem: String ="Spinner"
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
114
|
-
|
115
|
-
super.onCreate(savedInstanceState)
|
116
|
-
|
117
|
-
setContentView(R.layout.activity_main)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
val spinner = findViewById<Spinner>(R.id.spinner)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
// ArrayAdapter
|
126
|
-
|
127
|
-
val adapter = ArrayAdapter(applicationContext,
|
128
|
-
|
129
|
-
android.R.layout.simple_spinner_item, spinnerItems)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
// spinner に adapter をセット
|
138
|
-
|
139
|
-
// Kotlin Android Extensions
|
140
|
-
|
141
|
-
spinner.adapter = adapter
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
// リスナーを登録
|
146
|
-
|
147
|
-
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
148
|
-
|
149
|
-
// アイテムが選択された時
|
150
|
-
|
151
|
-
override fun onItemSelected(parent: AdapterView<*>?,
|
152
|
-
|
153
|
-
view: View?, position: Int, id: Long) {
|
154
|
-
|
155
|
-
val spinnerParent = parent as Spinner
|
156
|
-
|
157
|
-
val item = spinnerParent.selectedItem as String
|
158
|
-
|
159
|
-
// Kotlin Android Extensions
|
160
|
-
|
161
|
-
setectedItem = item
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
// アイテムが選択されなかった
|
168
|
-
|
169
|
-
override fun onNothingSelected(parent: AdapterView<*>?) {
|
170
|
-
|
171
|
-
//
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
//ボタンが押されたらデータをsubページに移動する
|
180
|
-
|
181
|
-
button.setOnClickListener {
|
182
|
-
|
183
|
-
if (editText.text != null) {
|
184
|
-
|
185
|
-
val intent = Intent(applicationContext, SubActivity::class.java)
|
186
|
-
|
187
|
-
val str = editText.text.toString()
|
188
|
-
|
189
|
-
val spinner_result = setectedItem
|
190
|
-
|
191
|
-
Log.d("debug",str)
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
intent.putExtra(EXTRA_MESSAGE, str)
|
196
|
-
|
197
|
-
intent.putExtra(EXTRA_SPINNER_RESULT, spinner_result)
|
198
|
-
|
199
|
-
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
200
|
-
|
201
|
-
editText.setText("")
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
```
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
SubActivity.kt
|
224
|
-
|
225
|
-
```kotlin
|
226
|
-
|
227
|
-
package com.example.diceroller
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
import androidx.appcompat.app.AppCompatActivity
|
232
|
-
|
233
|
-
import android.os.Bundle
|
234
|
-
|
235
|
-
import android.app.Activity
|
236
|
-
|
237
|
-
import android.content.Intent
|
238
|
-
|
239
|
-
import kotlinx.android.synthetic.main.activity_main.*
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
class SubActivity : AppCompatActivity() {
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
248
|
-
|
249
|
-
super.onCreate(savedInstanceState)
|
250
|
-
|
251
|
-
setContentView(R.layout.activity_sub)
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
// to get message from MainActivity
|
256
|
-
|
257
|
-
val intent = getIntent()
|
258
|
-
|
259
|
-
val message = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
260
|
-
|
261
|
-
val spinner_result = intent.extras?.getString(MainActivity.EXTRA_SPINNER_RESULT)?:""
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
textView.text = message
|
266
|
-
|
267
|
-
//textView.text = spinner_result
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
//移動前のページに遷移後の画面から入力された文字列を返す
|
272
|
-
|
273
|
-
button.setOnClickListener{
|
274
|
-
|
275
|
-
val intentSub = Intent()
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
if (editText.text != null) {
|
280
|
-
|
281
|
-
val str = message + editText.text.toString()
|
282
|
-
|
283
|
-
intentSub.putExtra(MainActivity.EXTRA_MESSAGE, str)
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
editText.setText("")
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
setResult(Activity.RESULT_OK, intentSub)
|
294
|
-
|
295
|
-
finish()
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
```
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
activity_sub.xml
|
310
|
-
|
311
|
-
```xml
|
312
|
-
|
313
|
-
<?xml version="1.0" encoding="utf-8"?>
|
314
|
-
|
315
|
-
<LinearLayout
|
316
|
-
|
317
|
-
xmlns:android="http://schemas.android.com/apk/res/android"
|
318
|
-
|
319
|
-
android:background="#fde"
|
320
|
-
|
321
|
-
android:orientation="vertical"
|
322
|
-
|
323
|
-
android:layout_width="match_parent"
|
324
|
-
|
325
|
-
android:layout_height="match_parent" >
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
<TextView
|
330
|
-
|
331
|
-
android:text="@string/sub"
|
332
|
-
|
333
|
-
android:textSize="24sp"
|
334
|
-
|
335
|
-
android:layout_width="match_parent"
|
336
|
-
|
337
|
-
android:layout_height="wrap_content"
|
338
|
-
|
339
|
-
android:gravity="center_horizontal"
|
340
|
-
|
341
|
-
android:layout_marginTop="40dp" />
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
<LinearLayout
|
346
|
-
|
347
|
-
android:layout_width="match_parent"
|
348
|
-
|
349
|
-
android:layout_height="wrap_content"
|
350
|
-
|
351
|
-
android:orientation="vertical">
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
<TextView
|
356
|
-
|
357
|
-
android:layout_width="wrap_content"
|
358
|
-
|
359
|
-
android:layout_height="wrap_content"
|
360
|
-
|
361
|
-
android:layout_margin="20dp"
|
362
|
-
|
363
|
-
android:text="@string/from_main"
|
364
|
-
|
365
|
-
android:textSize="24sp" />
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
<TextView
|
370
|
-
|
371
|
-
android:id="@+id/textView"
|
372
|
-
|
373
|
-
android:layout_width="220dp"
|
374
|
-
|
375
|
-
android:layout_height="wrap_content"
|
376
|
-
|
377
|
-
android:layout_margin="20dp"
|
378
|
-
|
379
|
-
android:textSize="24sp" />
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
<TextView
|
384
|
-
|
385
|
-
android:layout_width="wrap_content"
|
386
|
-
|
387
|
-
android:layout_height="wrap_content"
|
388
|
-
|
389
|
-
android:layout_margin="20dp"
|
390
|
-
|
391
|
-
android:text="@string/os_name"
|
392
|
-
|
393
|
-
android:textSize="24sp" />
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
<TextView
|
398
|
-
|
399
|
-
android:id="@+id/spinner"
|
400
|
-
|
401
|
-
android:layout_width="220dp"
|
402
|
-
|
403
|
-
android:layout_height="wrap_content"
|
404
|
-
|
405
|
-
android:layout_margin="20dp"
|
406
|
-
|
407
|
-
android:textSize="24sp" />
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
</LinearLayout>
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
<LinearLayout
|
418
|
-
|
419
|
-
android:layout_width="match_parent"
|
420
|
-
|
421
|
-
android:layout_height="wrap_content"
|
422
|
-
|
423
|
-
android:orientation="horizontal">
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
<TextView
|
428
|
-
|
429
|
-
android:layout_width="wrap_content"
|
430
|
-
|
431
|
-
android:layout_height="wrap_content"
|
432
|
-
|
433
|
-
android:layout_margin="20dp"
|
434
|
-
|
435
|
-
android:text="@string/to_main"
|
436
|
-
|
437
|
-
android:textSize="24sp" />
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
<EditText
|
442
|
-
|
443
|
-
android:id="@+id/editText"
|
444
|
-
|
445
|
-
android:layout_width="220dp"
|
446
|
-
|
447
|
-
android:layout_height="wrap_content"
|
448
|
-
|
449
|
-
android:layout_margin="20dp"
|
450
|
-
|
451
|
-
android:background="#fff"
|
452
|
-
|
453
|
-
android:hint="@string/hint2"
|
454
|
-
|
455
|
-
android:textSize="24sp" />
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
</LinearLayout>
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
<Button
|
464
|
-
|
465
|
-
android:id="@+id/button"
|
466
|
-
|
467
|
-
android:text="@string/back"
|
468
|
-
|
469
|
-
android:textSize="24sp"
|
470
|
-
|
471
|
-
android:layout_width="match_parent"
|
472
|
-
|
473
|
-
android:layout_height="wrap_content"
|
474
|
-
|
475
|
-
android:gravity="center_horizontal"
|
476
|
-
|
477
|
-
android:layout_margin="20dp" />
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
</LinearLayout>
|
482
|
-
|
483
|
-
```
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
465
|
|
492
466
|
|
493
467
|
|
5
ご回答を受けての修正とエラー
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,33 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
+
|
26
|
+
|
25
|
-
###
|
27
|
+
### ご回答を受けての修正とエラー
|
28
|
+
|
29
|
+
ご回答を受けて修正しましたが、`subActivity.lt`の
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
textView.text = message
|
34
|
+
|
35
|
+
//textView.text = spinner_result
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
Unresolved reference: textView
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
とエラーが出るようになってしまいました。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
エミュレータで「Enter」ボタンを押すと画面遷移はしますが、フォームとプルダウンの内容は移行画面で表示されていない状態です。
|
26
52
|
|
27
53
|
|
28
54
|
|
@@ -30,7 +56,7 @@
|
|
30
56
|
|
31
57
|
```kotlin
|
32
58
|
|
33
|
-
package com.example.
|
59
|
+
package com.example.diceroller
|
34
60
|
|
35
61
|
|
36
62
|
|
@@ -66,6 +92,8 @@
|
|
66
92
|
|
67
93
|
const val EXTRA_MESSAGE = "com.example.kotlinactivitydatatrans.MESSAGE"
|
68
94
|
|
95
|
+
const val EXTRA_SPINNER_RESULT = "com.example.kotlinactivitydatatrans.SPINNER_RESULT"
|
96
|
+
|
69
97
|
}
|
70
98
|
|
71
99
|
|
@@ -78,6 +106,8 @@
|
|
78
106
|
|
79
107
|
private val spinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
80
108
|
|
109
|
+
var setectedItem: String ="Spinner"
|
110
|
+
|
81
111
|
|
82
112
|
|
83
113
|
override fun onCreate(savedInstanceState: Bundle?) {
|
@@ -88,7 +118,7 @@
|
|
88
118
|
|
89
119
|
|
90
120
|
|
91
|
-
|
121
|
+
val spinner = findViewById<Spinner>(R.id.spinner)
|
92
122
|
|
93
123
|
|
94
124
|
|
@@ -128,7 +158,7 @@
|
|
128
158
|
|
129
159
|
// Kotlin Android Extensions
|
130
160
|
|
131
|
-
te
|
161
|
+
setectedItem = item
|
132
162
|
|
133
163
|
}
|
134
164
|
|
@@ -156,7 +186,7 @@
|
|
156
186
|
|
157
187
|
val str = editText.text.toString()
|
158
188
|
|
159
|
-
val spinner_result = te
|
189
|
+
val spinner_result = setectedItem
|
160
190
|
|
161
191
|
Log.d("debug",str)
|
162
192
|
|
@@ -164,14 +194,12 @@
|
|
164
194
|
|
165
195
|
intent.putExtra(EXTRA_MESSAGE, str)
|
166
196
|
|
167
|
-
intent.putExtra(EXTRA_
|
197
|
+
intent.putExtra(EXTRA_SPINNER_RESULT, spinner_result)
|
168
198
|
|
169
199
|
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
170
200
|
|
171
201
|
editText.setText("")
|
172
202
|
|
173
|
-
textView.setText("")
|
174
|
-
|
175
203
|
|
176
204
|
|
177
205
|
}
|
@@ -194,9 +222,9 @@
|
|
194
222
|
|
195
223
|
SubActivity.kt
|
196
224
|
|
197
|
-
```
|
225
|
+
```kotlin
|
198
|
-
|
226
|
+
|
199
|
-
package com.example.
|
227
|
+
package com.example.diceroller
|
200
228
|
|
201
229
|
|
202
230
|
|
@@ -230,13 +258,17 @@
|
|
230
258
|
|
231
259
|
val message = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
232
260
|
|
233
|
-
val spinner_result = intent.extras?.getString(MainActivity.EXTRA_
|
261
|
+
val spinner_result = intent.extras?.getString(MainActivity.EXTRA_SPINNER_RESULT)?:""
|
234
262
|
|
235
263
|
|
236
264
|
|
237
265
|
textView.text = message
|
238
266
|
|
239
|
-
|
267
|
+
//textView.text = spinner_result
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
//移動前のページに遷移後の画面から入力された文字列を返す
|
240
272
|
|
241
273
|
button.setOnClickListener{
|
242
274
|
|
@@ -270,299 +302,189 @@
|
|
270
302
|
|
271
303
|
}
|
272
304
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
/
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
android
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
/
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
/
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
o
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
i
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
SubActivity.kt
|
458
|
-
|
459
|
-
```kotlin
|
460
|
-
|
461
|
-
package com.example.spinner
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
import androidx.appcompat.app.AppCompatActivity
|
466
|
-
|
467
|
-
import android.os.Bundle
|
468
|
-
|
469
|
-
import android.app.Activity
|
470
|
-
|
471
|
-
import android.content.Intent
|
472
|
-
|
473
|
-
import kotlinx.android.synthetic.main.activity_main.*
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
class SubActivity : AppCompatActivity() {
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
482
|
-
|
483
|
-
super.onCreate(savedInstanceState)
|
484
|
-
|
485
|
-
setContentView(R.layout.activity_sub)
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
// to get message from MainActivity
|
490
|
-
|
491
|
-
val intent = getIntent()
|
492
|
-
|
493
|
-
val message = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
494
|
-
|
495
|
-
val spinner_result = intent.extras?.getString(MainActivity. EXTRA_SPINNER_RESULT)?:""
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
textView.text = message
|
500
|
-
|
501
|
-
textView.text = spinner_result
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
//移動前のページに遷移後の画面から入力された文字列を返す
|
506
|
-
|
507
|
-
button.setOnClickListener{
|
508
|
-
|
509
|
-
val intentSub = Intent()
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
if (editText.text != null) {
|
514
|
-
|
515
|
-
val str = message + editText.text.toString()
|
516
|
-
|
517
|
-
intentSub.putExtra(MainActivity.EXTRA_MESSAGE, str)
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
editText.setText("")
|
522
|
-
|
523
|
-
}
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
setResult(Activity.RESULT_OK, intentSub)
|
528
|
-
|
529
|
-
finish()
|
530
|
-
|
531
|
-
}
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
}
|
536
|
-
|
537
|
-
}
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
```
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
エミュレータで「Enter」ボタンを押すとアプリが閉じて、以下のメッセージが表示されるのは変わりません。
|
554
|
-
|
555
|
-
```
|
556
|
-
|
557
|
-
Spinner keeps stopping
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
App info
|
562
|
-
|
563
|
-
Close app
|
564
|
-
|
565
|
-
```
|
305
|
+
```
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
activity_sub.xml
|
310
|
+
|
311
|
+
```xml
|
312
|
+
|
313
|
+
<?xml version="1.0" encoding="utf-8"?>
|
314
|
+
|
315
|
+
<LinearLayout
|
316
|
+
|
317
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
318
|
+
|
319
|
+
android:background="#fde"
|
320
|
+
|
321
|
+
android:orientation="vertical"
|
322
|
+
|
323
|
+
android:layout_width="match_parent"
|
324
|
+
|
325
|
+
android:layout_height="match_parent" >
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
<TextView
|
330
|
+
|
331
|
+
android:text="@string/sub"
|
332
|
+
|
333
|
+
android:textSize="24sp"
|
334
|
+
|
335
|
+
android:layout_width="match_parent"
|
336
|
+
|
337
|
+
android:layout_height="wrap_content"
|
338
|
+
|
339
|
+
android:gravity="center_horizontal"
|
340
|
+
|
341
|
+
android:layout_marginTop="40dp" />
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
<LinearLayout
|
346
|
+
|
347
|
+
android:layout_width="match_parent"
|
348
|
+
|
349
|
+
android:layout_height="wrap_content"
|
350
|
+
|
351
|
+
android:orientation="vertical">
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
<TextView
|
356
|
+
|
357
|
+
android:layout_width="wrap_content"
|
358
|
+
|
359
|
+
android:layout_height="wrap_content"
|
360
|
+
|
361
|
+
android:layout_margin="20dp"
|
362
|
+
|
363
|
+
android:text="@string/from_main"
|
364
|
+
|
365
|
+
android:textSize="24sp" />
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
<TextView
|
370
|
+
|
371
|
+
android:id="@+id/textView"
|
372
|
+
|
373
|
+
android:layout_width="220dp"
|
374
|
+
|
375
|
+
android:layout_height="wrap_content"
|
376
|
+
|
377
|
+
android:layout_margin="20dp"
|
378
|
+
|
379
|
+
android:textSize="24sp" />
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
<TextView
|
384
|
+
|
385
|
+
android:layout_width="wrap_content"
|
386
|
+
|
387
|
+
android:layout_height="wrap_content"
|
388
|
+
|
389
|
+
android:layout_margin="20dp"
|
390
|
+
|
391
|
+
android:text="@string/os_name"
|
392
|
+
|
393
|
+
android:textSize="24sp" />
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
<TextView
|
398
|
+
|
399
|
+
android:id="@+id/spinner"
|
400
|
+
|
401
|
+
android:layout_width="220dp"
|
402
|
+
|
403
|
+
android:layout_height="wrap_content"
|
404
|
+
|
405
|
+
android:layout_margin="20dp"
|
406
|
+
|
407
|
+
android:textSize="24sp" />
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
</LinearLayout>
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
<LinearLayout
|
418
|
+
|
419
|
+
android:layout_width="match_parent"
|
420
|
+
|
421
|
+
android:layout_height="wrap_content"
|
422
|
+
|
423
|
+
android:orientation="horizontal">
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
<TextView
|
428
|
+
|
429
|
+
android:layout_width="wrap_content"
|
430
|
+
|
431
|
+
android:layout_height="wrap_content"
|
432
|
+
|
433
|
+
android:layout_margin="20dp"
|
434
|
+
|
435
|
+
android:text="@string/to_main"
|
436
|
+
|
437
|
+
android:textSize="24sp" />
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
<EditText
|
442
|
+
|
443
|
+
android:id="@+id/editText"
|
444
|
+
|
445
|
+
android:layout_width="220dp"
|
446
|
+
|
447
|
+
android:layout_height="wrap_content"
|
448
|
+
|
449
|
+
android:layout_margin="20dp"
|
450
|
+
|
451
|
+
android:background="#fff"
|
452
|
+
|
453
|
+
android:hint="@string/hint2"
|
454
|
+
|
455
|
+
android:textSize="24sp" />
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
</LinearLayout>
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
<Button
|
464
|
+
|
465
|
+
android:id="@+id/button"
|
466
|
+
|
467
|
+
android:text="@string/back"
|
468
|
+
|
469
|
+
android:textSize="24sp"
|
470
|
+
|
471
|
+
android:layout_width="match_parent"
|
472
|
+
|
473
|
+
android:layout_height="wrap_content"
|
474
|
+
|
475
|
+
android:gravity="center_horizontal"
|
476
|
+
|
477
|
+
android:layout_margin="20dp" />
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
</LinearLayout>
|
482
|
+
|
483
|
+
```
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
566
488
|
|
567
489
|
|
568
490
|
|
4
ご回答を受けての修正とエラーの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -348,7 +348,7 @@
|
|
348
348
|
|
349
349
|
|
350
350
|
|
351
|
-
|
351
|
+
val spinner = findViewById<Spinner>(R.id.spinner)
|
352
352
|
|
353
353
|
|
354
354
|
|
@@ -498,7 +498,11 @@
|
|
498
498
|
|
499
499
|
textView.text = message
|
500
500
|
|
501
|
-
|
501
|
+
textView.text = spinner_result
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
//移動前のページに遷移後の画面から入力された文字列を返す
|
502
506
|
|
503
507
|
button.setOnClickListener{
|
504
508
|
|
@@ -534,6 +538,10 @@
|
|
534
538
|
|
535
539
|
|
536
540
|
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
537
545
|
```
|
538
546
|
|
539
547
|
|
3
ご回答を受けての修正とエラー
test
CHANGED
File without changes
|
test
CHANGED
@@ -278,6 +278,288 @@
|
|
278
278
|
|
279
279
|
|
280
280
|
|
281
|
+
### ご回答を受けての修正とエラー
|
282
|
+
|
283
|
+
ご回答を受けて修正しましたが、エラーは変わらず、`layoutのxml`の前に`.kt`ファイルのコードに問題があると思うのですが、エラーメッセージがコード中に現れないので、修正箇所が特定できず困っています。
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
MainActivity.kt
|
288
|
+
|
289
|
+
```kotlin
|
290
|
+
|
291
|
+
package com.example.spinner
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
import androidx.appcompat.app.AppCompatActivity
|
296
|
+
|
297
|
+
import android.os.Bundle
|
298
|
+
|
299
|
+
import android.app.Activity
|
300
|
+
|
301
|
+
import android.content.Intent
|
302
|
+
|
303
|
+
import android.util.Log
|
304
|
+
|
305
|
+
import android.view.View
|
306
|
+
|
307
|
+
import android.widget.AdapterView
|
308
|
+
|
309
|
+
import android.widget.Spinner
|
310
|
+
|
311
|
+
import android.widget.ArrayAdapter
|
312
|
+
|
313
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
314
|
+
|
315
|
+
import android.widget.AdapterView.OnItemSelectedListener
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
class MainActivity : AppCompatActivity() {
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
companion object {
|
324
|
+
|
325
|
+
const val EXTRA_MESSAGE = "com.example.kotlinactivitydatatrans.MESSAGE"
|
326
|
+
|
327
|
+
const val EXTRA_SPINNER_RESULT = "com.example.kotlinactivitydatatrans.SPINNER_RESULT"
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
//フォームからのデータ
|
334
|
+
|
335
|
+
private val RESULT_SUBACTIVITY = 1000
|
336
|
+
|
337
|
+
// スピナーの選択肢
|
338
|
+
|
339
|
+
private val spinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
344
|
+
|
345
|
+
super.onCreate(savedInstanceState)
|
346
|
+
|
347
|
+
setContentView(R.layout.activity_main)
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
//val spinner = findViewById<Spinner>(R.id.spinner)
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
// ArrayAdapter
|
356
|
+
|
357
|
+
val adapter = ArrayAdapter(applicationContext,
|
358
|
+
|
359
|
+
android.R.layout.simple_spinner_item, spinnerItems)
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
// spinner に adapter をセット
|
368
|
+
|
369
|
+
// Kotlin Android Extensions
|
370
|
+
|
371
|
+
spinner.adapter = adapter
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
// リスナーを登録
|
376
|
+
|
377
|
+
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
378
|
+
|
379
|
+
// アイテムが選択された時
|
380
|
+
|
381
|
+
override fun onItemSelected(parent: AdapterView<*>?,
|
382
|
+
|
383
|
+
view: View?, position: Int, id: Long) {
|
384
|
+
|
385
|
+
val spinnerParent = parent as Spinner
|
386
|
+
|
387
|
+
val item = spinnerParent.selectedItem as String
|
388
|
+
|
389
|
+
// Kotlin Android Extensions
|
390
|
+
|
391
|
+
textView.text = item
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
// アイテムが選択されなかった
|
398
|
+
|
399
|
+
override fun onNothingSelected(parent: AdapterView<*>?) {
|
400
|
+
|
401
|
+
//
|
402
|
+
|
403
|
+
}
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
//ボタンが押されたらデータをsubページに移動する
|
410
|
+
|
411
|
+
button.setOnClickListener {
|
412
|
+
|
413
|
+
if (editText.text != null) {
|
414
|
+
|
415
|
+
val intent = Intent(applicationContext, SubActivity::class.java)
|
416
|
+
|
417
|
+
val str = editText.text.toString()
|
418
|
+
|
419
|
+
//textView.text = itemで登録されたitemを次の画面に遷移させたい
|
420
|
+
|
421
|
+
val spinner_result = textView.text.toString()
|
422
|
+
|
423
|
+
Log.d("debug",str)
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
intent.putExtra(EXTRA_MESSAGE, str)
|
428
|
+
|
429
|
+
intent.putExtra(EXTRA_SPINNER_RESULT, spinner_result)
|
430
|
+
|
431
|
+
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
432
|
+
|
433
|
+
editText.setText("")
|
434
|
+
|
435
|
+
textView.setText("")
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
```
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
SubActivity.kt
|
458
|
+
|
459
|
+
```kotlin
|
460
|
+
|
461
|
+
package com.example.spinner
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
import androidx.appcompat.app.AppCompatActivity
|
466
|
+
|
467
|
+
import android.os.Bundle
|
468
|
+
|
469
|
+
import android.app.Activity
|
470
|
+
|
471
|
+
import android.content.Intent
|
472
|
+
|
473
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
class SubActivity : AppCompatActivity() {
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
482
|
+
|
483
|
+
super.onCreate(savedInstanceState)
|
484
|
+
|
485
|
+
setContentView(R.layout.activity_sub)
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
// to get message from MainActivity
|
490
|
+
|
491
|
+
val intent = getIntent()
|
492
|
+
|
493
|
+
val message = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
494
|
+
|
495
|
+
val spinner_result = intent.extras?.getString(MainActivity. EXTRA_SPINNER_RESULT)?:""
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
textView.text = message
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
button.setOnClickListener{
|
504
|
+
|
505
|
+
val intentSub = Intent()
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
if (editText.text != null) {
|
510
|
+
|
511
|
+
val str = message + editText.text.toString()
|
512
|
+
|
513
|
+
intentSub.putExtra(MainActivity.EXTRA_MESSAGE, str)
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
editText.setText("")
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
setResult(Activity.RESULT_OK, intentSub)
|
524
|
+
|
525
|
+
finish()
|
526
|
+
|
527
|
+
}
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
}
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
```
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
エミュレータで「Enter」ボタンを押すとアプリが閉じて、以下のメッセージが表示されるのは変わりません。
|
546
|
+
|
547
|
+
```
|
548
|
+
|
549
|
+
Spinner keeps stopping
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
App info
|
554
|
+
|
555
|
+
Close app
|
556
|
+
|
557
|
+
```
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
|
281
563
|
|
282
564
|
|
283
565
|
### 補足情報(FW/ツールのバージョンなど)
|
2
エラーと現状のコードの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,446 +18,264 @@
|
|
18
18
|
|
19
19
|
### 発生している問題・エラーメッセージ
|
20
20
|
|
21
|
-
Main
|
21
|
+
ビルドでエラーは出ず、エミュレータで実行できるのですが、`Mainページ`でフォーム(EditText)に入力し、プルダウン(spinner)を選択して、ボタンを押すと、`Subページ`に移動せずにアプリが終了してAndroidのホーム画面が表示されてしまう問題が解決できません。
|
22
|
+
|
23
|
+
|
24
|
+
|
22
|
-
|
25
|
+
### 該当のソースコード
|
26
|
+
|
27
|
+
|
28
|
+
|
23
|
-
|
29
|
+
MainActivity.kt
|
30
|
+
|
31
|
+
```kotlin
|
32
|
+
|
33
|
+
package com.example.spinner
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
import androidx.appcompat.app.AppCompatActivity
|
38
|
+
|
39
|
+
import android.os.Bundle
|
40
|
+
|
41
|
+
import android.app.Activity
|
42
|
+
|
43
|
+
import android.content.Intent
|
44
|
+
|
45
|
+
import android.util.Log
|
46
|
+
|
47
|
+
import android.view.View
|
48
|
+
|
49
|
+
import android.widget.AdapterView
|
50
|
+
|
51
|
+
import android.widget.Spinner
|
52
|
+
|
53
|
+
import android.widget.ArrayAdapter
|
54
|
+
|
55
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
56
|
+
|
57
|
+
import android.widget.AdapterView.OnItemSelectedListener
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
class MainActivity : AppCompatActivity() {
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
companion object {
|
66
|
+
|
67
|
+
const val EXTRA_MESSAGE = "com.example.kotlinactivitydatatrans.MESSAGE"
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//フォームからのデータ
|
74
|
+
|
75
|
+
private val RESULT_SUBACTIVITY = 1000
|
76
|
+
|
77
|
+
// スピナーの選択肢
|
78
|
+
|
79
|
+
private val spinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
84
|
+
|
85
|
+
super.onCreate(savedInstanceState)
|
86
|
+
|
87
|
+
setContentView(R.layout.activity_main)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
//val spinner = findViewById<Spinner>(R.id.spinner)
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
// ArrayAdapter
|
96
|
+
|
97
|
+
val adapter = ArrayAdapter(applicationContext,
|
98
|
+
|
99
|
+
android.R.layout.simple_spinner_item, spinnerItems)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
// spinner に adapter をセット
|
108
|
+
|
109
|
+
// Kotlin Android Extensions
|
110
|
+
|
111
|
+
spinner.adapter = adapter
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
// リスナーを登録
|
116
|
+
|
117
|
+
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
118
|
+
|
119
|
+
// アイテムが選択された時
|
120
|
+
|
121
|
+
override fun onItemSelected(parent: AdapterView<*>?,
|
122
|
+
|
123
|
+
view: View?, position: Int, id: Long) {
|
124
|
+
|
125
|
+
val spinnerParent = parent as Spinner
|
126
|
+
|
127
|
+
val item = spinnerParent.selectedItem as String
|
128
|
+
|
129
|
+
// Kotlin Android Extensions
|
130
|
+
|
131
|
+
textView.text = item
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
// アイテムが選択されなかった
|
138
|
+
|
139
|
+
override fun onNothingSelected(parent: AdapterView<*>?) {
|
140
|
+
|
141
|
+
//
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//ボタンが押されたらデータをsubページに移動する
|
150
|
+
|
151
|
+
button.setOnClickListener {
|
152
|
+
|
153
|
+
if (editText.text != null) {
|
154
|
+
|
155
|
+
val intent = Intent(applicationContext, SubActivity::class.java)
|
156
|
+
|
157
|
+
val str = editText.text.toString()
|
158
|
+
|
159
|
+
val spinner_result = textView.text.toString()
|
160
|
+
|
161
|
+
Log.d("debug",str)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
intent.putExtra(EXTRA_MESSAGE, str)
|
166
|
+
|
167
|
+
intent.putExtra(EXTRA_MESSAGE, spinner_result)
|
168
|
+
|
169
|
+
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
170
|
+
|
171
|
+
editText.setText("")
|
172
|
+
|
173
|
+
textView.setText("")
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
}
|
24
190
|
|
25
191
|
```
|
26
192
|
|
193
|
+
|
194
|
+
|
195
|
+
SubActivity.kt
|
196
|
+
|
197
|
+
```Kotlin
|
198
|
+
|
199
|
+
package com.example.spinner
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
import androidx.appcompat.app.AppCompatActivity
|
204
|
+
|
205
|
+
import android.os.Bundle
|
206
|
+
|
207
|
+
import android.app.Activity
|
208
|
+
|
209
|
+
import android.content.Intent
|
210
|
+
|
211
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
class SubActivity : AppCompatActivity() {
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
220
|
+
|
221
|
+
super.onCreate(savedInstanceState)
|
222
|
+
|
223
|
+
setContentView(R.layout.activity_sub)
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
// to get message from MainActivity
|
228
|
+
|
27
|
-
intent
|
229
|
+
val intent = getIntent()
|
230
|
+
|
231
|
+
val message = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
232
|
+
|
233
|
+
val spinner_result = intent.extras?.getString(MainActivity.EXTRA_MESSAGE)?:""
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
textView.text = message
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
button.setOnClickListener{
|
242
|
+
|
243
|
+
val intentSub = Intent()
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
if (editText.text != null) {
|
248
|
+
|
249
|
+
val str = message + editText.text.toString()
|
250
|
+
|
251
|
+
intentSub.putExtra(MainActivity.EXTRA_MESSAGE, str)
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
editText.setText("")
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
setResult(Activity.RESULT_OK, intentSub)
|
262
|
+
|
263
|
+
finish()
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
28
276
|
|
29
277
|
```
|
30
278
|
|
31
|
-
とエラーメッセージが出ました。
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
### 該当のソースコード
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
MainActivity.kt
|
42
|
-
|
43
|
-
```kotlin
|
44
|
-
|
45
|
-
package com.example.diceroller
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
import androidx.appcompat.app.AppCompatActivity
|
50
|
-
|
51
|
-
import android.os.Bundle
|
52
|
-
|
53
|
-
import android.app.Activity
|
54
|
-
|
55
|
-
import android.content.Intent
|
56
|
-
|
57
|
-
import android.util.Log
|
58
|
-
|
59
|
-
import android.view.View
|
60
|
-
|
61
|
-
import android.widget.AdapterView
|
62
|
-
|
63
|
-
import android.widget.Spinner
|
64
|
-
|
65
|
-
import android.widget.ArrayAdapter
|
66
|
-
|
67
|
-
import kotlinx.android.synthetic.main.activity_main.*
|
68
|
-
|
69
|
-
import android.widget.AdapterView.OnItemSelectedListener
|
70
|
-
|
71
|
-
import androidx.core.app.ComponentActivity
|
72
|
-
|
73
|
-
import androidx.core.app.ComponentActivity.ExtraData
|
74
|
-
|
75
|
-
import androidx.core.content.ContextCompat.getSystemService
|
76
|
-
|
77
|
-
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
|
78
|
-
|
79
|
-
import sun.jvm.hotspot.utilities.IntArray
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
class MainActivity : AppCompatActivity() {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
companion object {
|
88
|
-
|
89
|
-
const val EXTRA_MESSAGE = "com.example.kotlinactivitydatatrans.MESSAGE"
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
private val RESULT_SUBACTIVITY = 1000
|
96
|
-
|
97
|
-
private val SpinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
102
|
-
|
103
|
-
super.onCreate(savedInstanceState)
|
104
|
-
|
105
|
-
setContentView(R.layout.activity_main)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
button.setOnClickListener {
|
110
|
-
|
111
|
-
if (editText.text != null) {
|
112
|
-
|
113
|
-
val intent = Intent(applicationContext, SubActivity::class.java)
|
114
|
-
|
115
|
-
val str = editText.text.toString()
|
116
|
-
|
117
|
-
Log.d("debug",str)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
intent.putExtra(EXTRA_MESSAGE, str)
|
122
|
-
|
123
|
-
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
124
|
-
|
125
|
-
startActivityForResult(intent, SpinnerItems)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
editText.setText("")
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
// ArrayAdapter
|
140
|
-
|
141
|
-
val adapter = ArrayAdapter(applicationContext,
|
142
|
-
|
143
|
-
android.R.layout.simple_spinner_item, spinnerItems)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
// spinner に adapter をセット
|
152
|
-
|
153
|
-
spinner.adapter = adapter
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
// リスナーを登録
|
158
|
-
|
159
|
-
spinner.onItemSelectedListener = object : OnItemSelectedListener {
|
160
|
-
|
161
|
-
// アイテムが選択された時
|
162
|
-
|
163
|
-
override fun onItemSelected(
|
164
|
-
|
165
|
-
parent: AdapterView<*>,
|
166
|
-
|
167
|
-
view: View, position: Int, id: Long
|
168
|
-
|
169
|
-
) {
|
170
|
-
|
171
|
-
val spinner = parent as Spinner
|
172
|
-
|
173
|
-
val item = spinner.selectedItem as String
|
174
|
-
|
175
|
-
textView.text = item
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
// アイテムが選択されなかった
|
182
|
-
|
183
|
-
override fun onNothingSelected(parent: AdapterView<*>) {
|
184
|
-
|
185
|
-
//
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
// to get a result form SubActivity
|
198
|
-
|
199
|
-
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
|
200
|
-
|
201
|
-
super.onActivityResult(requestCode, resultCode, intent)
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
if (resultCode == Activity.RESULT_OK &&
|
206
|
-
|
207
|
-
requestCode == RESULT_SUBACTIVITY && intent != null) {
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
val res = intent.extras?.getString(EXTRA_MESSAGE)?: ""
|
212
|
-
|
213
|
-
textView.text = res
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
if (resultCode == Activity.RESULT_OK &&
|
226
|
-
|
227
|
-
requestCode == SpinnerItems && intent != null) {
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
val res = intent.extras?.getString(EXTRA_MESSAGE)?: ""
|
232
|
-
|
233
|
-
textView.text = res
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
```
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
activity_main.xml
|
248
|
-
|
249
|
-
```xml
|
250
|
-
|
251
|
-
<?xml version="1.0" encoding="utf-8"?>
|
252
|
-
|
253
|
-
<LinearLayout
|
254
|
-
|
255
|
-
xmlns:android="http://schemas.android.com/apk/res/android"
|
256
|
-
|
257
|
-
xmlns:tools="http://schemas.android.com/tools"
|
258
|
-
|
259
|
-
android:layout_width="match_parent"
|
260
|
-
|
261
|
-
android:layout_height="match_parent"
|
262
|
-
|
263
|
-
android:background="#dfe"
|
264
|
-
|
265
|
-
android:orientation="vertical"
|
266
|
-
|
267
|
-
tools:context=".MainActivity">
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
<TextView
|
272
|
-
|
273
|
-
android:text="@string/main"
|
274
|
-
|
275
|
-
android:textSize="24sp"
|
276
|
-
|
277
|
-
android:layout_width="match_parent"
|
278
|
-
|
279
|
-
android:layout_height="wrap_content"
|
280
|
-
|
281
|
-
android:gravity="center_horizontal"
|
282
|
-
|
283
|
-
android:layout_marginTop="40dp" />
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
<LinearLayout
|
288
|
-
|
289
|
-
android:layout_width="match_parent"
|
290
|
-
|
291
|
-
android:layout_height="wrap_content"
|
292
|
-
|
293
|
-
android:orientation="vertical">
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
<TextView
|
300
|
-
|
301
|
-
android:layout_width="wrap_content"
|
302
|
-
|
303
|
-
android:layout_height="wrap_content"
|
304
|
-
|
305
|
-
android:layout_margin="20dp"
|
306
|
-
|
307
|
-
android:text="@string/to_sub"
|
308
|
-
|
309
|
-
android:textSize="24sp" />
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
<EditText
|
314
|
-
|
315
|
-
android:id="@+id/editText"
|
316
|
-
|
317
|
-
android:layout_width="220dp"
|
318
|
-
|
319
|
-
android:layout_height="wrap_content"
|
320
|
-
|
321
|
-
android:layout_margin="20dp"
|
322
|
-
|
323
|
-
android:background="#fff"
|
324
|
-
|
325
|
-
android:hint="@string/hint1"
|
326
|
-
|
327
|
-
android:textSize="24sp" />
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
<TextView
|
332
|
-
|
333
|
-
android:layout_width="wrap_content"
|
334
|
-
|
335
|
-
android:layout_height="wrap_content"
|
336
|
-
|
337
|
-
android:layout_margin="20dp"
|
338
|
-
|
339
|
-
android:text="@string/age"
|
340
|
-
|
341
|
-
android:textSize="24sp" />
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
<Spinner
|
346
|
-
|
347
|
-
android:id="@+id/spinner"
|
348
|
-
|
349
|
-
android:layout_width="200dp"
|
350
|
-
|
351
|
-
android:layout_height="wrap_content"
|
352
|
-
|
353
|
-
android:layout_margin="20dp"
|
354
|
-
|
355
|
-
android:background="#fff" />
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
</LinearLayout>
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
<LinearLayout
|
364
|
-
|
365
|
-
android:layout_width="match_parent"
|
366
|
-
|
367
|
-
android:layout_height="wrap_content"
|
368
|
-
|
369
|
-
android:orientation="vertical">
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
<TextView
|
374
|
-
|
375
|
-
android:layout_width="wrap_content"
|
376
|
-
|
377
|
-
android:layout_height="wrap_content"
|
378
|
-
|
379
|
-
android:layout_margin="20dp"
|
380
|
-
|
381
|
-
android:text="@string/from_sub"
|
382
|
-
|
383
|
-
android:textSize="24sp" />
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
<TextView
|
388
|
-
|
389
|
-
android:id="@+id/textView"
|
390
|
-
|
391
|
-
android:layout_width="220dp"
|
392
|
-
|
393
|
-
android:layout_height="wrap_content"
|
394
|
-
|
395
|
-
android:layout_margin="20dp"
|
396
|
-
|
397
|
-
android:textSize="24sp" />
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
</LinearLayout>
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
<Button
|
406
|
-
|
407
|
-
android:id="@+id/button"
|
408
|
-
|
409
|
-
android:text="@string/move"
|
410
|
-
|
411
|
-
android:textSize="24sp"
|
412
|
-
|
413
|
-
android:layout_width="match_parent"
|
414
|
-
|
415
|
-
android:layout_height="wrap_content"
|
416
|
-
|
417
|
-
android:gravity="center"
|
418
|
-
|
419
|
-
android:layout_margin="20dp" />
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
</LinearLayout>
|
424
|
-
|
425
|
-
```
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
### 試したこと
|
434
|
-
|
435
|
-
プルダウンで選択されたものを
|
436
|
-
|
437
|
-
```
|
438
|
-
|
439
|
-
// アイテムが選択された時
|
440
|
-
|
441
|
-
override fun onItemSelected(
|
442
|
-
|
443
|
-
parent: AdapterView<*>,
|
444
|
-
|
445
|
-
view: View, position: Int, id: Long
|
446
|
-
|
447
|
-
) {
|
448
|
-
|
449
|
-
val spinner = parent as Spinner
|
450
|
-
|
451
|
-
val item = spinner.selectedItem as String
|
452
|
-
|
453
|
-
textView.text = item
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
```
|
458
|
-
|
459
|
-
の`item`から取ってきたいのですが、方法がわからない状態です。
|
460
|
-
|
461
279
|
|
462
280
|
|
463
281
|
|
1
エラーと該当のソースコードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,23 +18,31 @@
|
|
18
18
|
|
19
19
|
### 発生している問題・エラーメッセージ
|
20
20
|
|
21
|
+
MainActivity.ktの文字列を次のページで表示させる`startActivityForResult(intent, RESULT_SUBACTIVITY)`に倣って、43行目に`startActivityForResult(intent, SpinnerItems)`と明記しましたが、
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
intent requires int
|
28
|
+
|
29
|
+
```
|
30
|
+
|
21
|
-
|
31
|
+
とエラーメッセージが出ました。
|
22
|
-
|
23
|
-
|
32
|
+
|
33
|
+
|
24
34
|
|
25
35
|
|
26
36
|
|
27
37
|
### 該当のソースコード
|
28
38
|
|
29
|
-
現在、エラーが出ないビルドできる状態のプログラムです。
|
30
|
-
|
31
39
|
|
32
40
|
|
33
41
|
MainActivity.kt
|
34
42
|
|
35
43
|
```kotlin
|
36
44
|
|
37
|
-
package com.example.
|
45
|
+
package com.example.diceroller
|
38
46
|
|
39
47
|
|
40
48
|
|
@@ -58,6 +66,18 @@
|
|
58
66
|
|
59
67
|
import kotlinx.android.synthetic.main.activity_main.*
|
60
68
|
|
69
|
+
import android.widget.AdapterView.OnItemSelectedListener
|
70
|
+
|
71
|
+
import androidx.core.app.ComponentActivity
|
72
|
+
|
73
|
+
import androidx.core.app.ComponentActivity.ExtraData
|
74
|
+
|
75
|
+
import androidx.core.content.ContextCompat.getSystemService
|
76
|
+
|
77
|
+
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
|
78
|
+
|
79
|
+
import sun.jvm.hotspot.utilities.IntArray
|
80
|
+
|
61
81
|
|
62
82
|
|
63
83
|
class MainActivity : AppCompatActivity() {
|
@@ -74,7 +94,7 @@
|
|
74
94
|
|
75
95
|
private val RESULT_SUBACTIVITY = 1000
|
76
96
|
|
77
|
-
private val
|
97
|
+
private val SpinnerItems = arrayOf("Spinner", "Android", "Apple", "Windows")
|
78
98
|
|
79
99
|
|
80
100
|
|
@@ -102,6 +122,8 @@
|
|
102
122
|
|
103
123
|
startActivityForResult(intent, RESULT_SUBACTIVITY)
|
104
124
|
|
125
|
+
startActivityForResult(intent, SpinnerItems)
|
126
|
+
|
105
127
|
|
106
128
|
|
107
129
|
editText.setText("")
|
@@ -128,12 +150,46 @@
|
|
128
150
|
|
129
151
|
// spinner に adapter をセット
|
130
152
|
|
131
|
-
// Kotlin Android Extensions
|
132
|
-
|
133
153
|
spinner.adapter = adapter
|
134
154
|
|
135
155
|
|
136
156
|
|
157
|
+
// リスナーを登録
|
158
|
+
|
159
|
+
spinner.onItemSelectedListener = object : OnItemSelectedListener {
|
160
|
+
|
161
|
+
// アイテムが選択された時
|
162
|
+
|
163
|
+
override fun onItemSelected(
|
164
|
+
|
165
|
+
parent: AdapterView<*>,
|
166
|
+
|
167
|
+
view: View, position: Int, id: Long
|
168
|
+
|
169
|
+
) {
|
170
|
+
|
171
|
+
val spinner = parent as Spinner
|
172
|
+
|
173
|
+
val item = spinner.selectedItem as String
|
174
|
+
|
175
|
+
textView.text = item
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
// アイテムが選択されなかった
|
182
|
+
|
183
|
+
override fun onNothingSelected(parent: AdapterView<*>) {
|
184
|
+
|
185
|
+
//
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
137
193
|
}
|
138
194
|
|
139
195
|
|
@@ -158,6 +214,26 @@
|
|
158
214
|
|
159
215
|
}
|
160
216
|
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
if (resultCode == Activity.RESULT_OK &&
|
226
|
+
|
227
|
+
requestCode == SpinnerItems && intent != null) {
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
val res = intent.extras?.getString(EXTRA_MESSAGE)?: ""
|
232
|
+
|
233
|
+
textView.text = res
|
234
|
+
|
235
|
+
}
|
236
|
+
|
161
237
|
}
|
162
238
|
|
163
239
|
|
@@ -350,268 +426,42 @@
|
|
350
426
|
|
351
427
|
|
352
428
|
|
353
|
-
|
429
|
+
|
354
|
-
|
355
|
-
```xml
|
356
|
-
|
357
|
-
<?xml version="1.0" encoding="utf-8"?>
|
358
|
-
|
359
|
-
<LinearLayout
|
360
|
-
|
361
|
-
xmlns:android="http://schemas.android.com/apk/res/android"
|
362
|
-
|
363
|
-
android:background="#fde"
|
364
|
-
|
365
|
-
android:orientation="vertical"
|
366
|
-
|
367
|
-
android:layout_width="match_parent"
|
368
|
-
|
369
|
-
android:layout_height="match_parent" >
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
<TextView
|
374
|
-
|
375
|
-
android:text="@string/sub"
|
376
|
-
|
377
|
-
android:textSize="24sp"
|
378
|
-
|
379
|
-
android:layout_width="match_parent"
|
380
|
-
|
381
|
-
android:layout_height="wrap_content"
|
382
|
-
|
383
|
-
android:gravity="center_horizontal"
|
384
|
-
|
385
|
-
android:layout_marginTop="40dp" />
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
<LinearLayout
|
390
|
-
|
391
|
-
android:layout_width="match_parent"
|
392
|
-
|
393
|
-
android:layout_height="wrap_content"
|
394
|
-
|
395
|
-
android:orientation="vertical">
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
<TextView
|
400
|
-
|
401
|
-
android:layout_width="wrap_content"
|
402
|
-
|
403
|
-
android:layout_height="wrap_content"
|
404
|
-
|
405
|
-
android:layout_margin="20dp"
|
406
|
-
|
407
|
-
android:text="@string/from_main"
|
408
|
-
|
409
|
-
android:textSize="24sp" />
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
<TextView
|
414
|
-
|
415
|
-
android:id="@+id/textView"
|
416
|
-
|
417
|
-
android:layout_width="220dp"
|
418
|
-
|
419
|
-
android:layout_height="wrap_content"
|
420
|
-
|
421
|
-
android:layout_margin="20dp"
|
422
|
-
|
423
|
-
android:textSize="24sp" />
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
<TextView
|
428
|
-
|
429
|
-
android:layout_width="wrap_content"
|
430
|
-
|
431
|
-
android:layout_height="wrap_content"
|
432
|
-
|
433
|
-
android:layout_margin="20dp"
|
434
|
-
|
435
|
-
android:text="OS Name"
|
436
|
-
|
437
|
-
android:textSize="24sp" />
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
<TextView
|
442
|
-
|
443
|
-
android:id="@+id/spinner"
|
444
|
-
|
445
|
-
android:layout_width="220dp"
|
446
|
-
|
447
|
-
android:layout_height="wrap_content"
|
448
|
-
|
449
|
-
android:layout_margin="20dp"
|
450
|
-
|
451
|
-
android:textSize="24sp" />
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
</LinearLayout>
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
<LinearLayout
|
462
|
-
|
463
|
-
android:layout_width="match_parent"
|
464
|
-
|
465
|
-
android:layout_height="wrap_content"
|
466
|
-
|
467
|
-
android:orientation="horizontal">
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
<TextView
|
472
|
-
|
473
|
-
android:layout_width="wrap_content"
|
474
|
-
|
475
|
-
android:layout_height="wrap_content"
|
476
|
-
|
477
|
-
android:layout_margin="20dp"
|
478
|
-
|
479
|
-
android:text="@string/to_main"
|
480
|
-
|
481
|
-
android:textSize="24sp" />
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
<EditText
|
486
|
-
|
487
|
-
android:id="@+id/editText"
|
488
|
-
|
489
|
-
android:layout_width="220dp"
|
490
|
-
|
491
|
-
android:layout_height="wrap_content"
|
492
|
-
|
493
|
-
android:layout_margin="20dp"
|
494
|
-
|
495
|
-
android:background="#fff"
|
496
|
-
|
497
|
-
android:hint="@string/hint2"
|
498
|
-
|
499
|
-
android:textSize="24sp" />
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
</LinearLayout>
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
<Button
|
508
|
-
|
509
|
-
android:id="@+id/button"
|
510
|
-
|
511
|
-
android:text="@string/back"
|
512
|
-
|
513
|
-
android:textSize="24sp"
|
514
|
-
|
515
|
-
android:layout_width="match_parent"
|
516
|
-
|
517
|
-
android:layout_height="wrap_content"
|
518
|
-
|
519
|
-
android:gravity="center_horizontal"
|
520
|
-
|
521
|
-
android:layout_margin="20dp" />
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
</LinearLayout>
|
526
|
-
|
527
|
-
```
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
strings.xml
|
532
|
-
|
533
|
-
```
|
534
|
-
|
535
|
-
<resources>
|
536
|
-
|
537
|
-
<string name="button">YourAppName</string>
|
538
|
-
|
539
|
-
<string name="main">Personal Info</string>
|
540
|
-
|
541
|
-
<string name="sub">Sub Activity</string>
|
542
|
-
|
543
|
-
<string name="hint1">Message to Sub</string>
|
544
|
-
|
545
|
-
<string name="hint2">Message to Main</string>
|
546
|
-
|
547
|
-
<string name="to_main">" to Main"</string>
|
548
|
-
|
549
|
-
<string name="from_main">"Nickname"</string>
|
550
|
-
|
551
|
-
<string name="to_sub">" Please enter your nickname"</string>
|
552
|
-
|
553
|
-
<string name="age">" Please select your OS"</string>
|
554
|
-
|
555
|
-
<string name="from_sub">"from Sub"</string>
|
556
|
-
|
557
|
-
<string name="move">Enter</string>
|
558
|
-
|
559
|
-
<string name="back">back</string>
|
560
|
-
|
561
|
-
<string name="app_name">Screen Transit</string>
|
562
|
-
|
563
|
-
</resources>
|
564
|
-
|
565
|
-
```
|
566
430
|
|
567
431
|
|
568
432
|
|
569
433
|
### 試したこと
|
570
434
|
|
571
|
-
|
435
|
+
プルダウンで選択されたものを
|
572
|
-
|
573
|
-
|
574
|
-
|
436
|
+
|
575
|
-
```
|
437
|
+
```
|
576
|
-
|
577
|
-
// リスナーを登録
|
578
|
-
|
579
|
-
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
580
438
|
|
581
439
|
// アイテムが選択された時
|
582
440
|
|
441
|
+
override fun onItemSelected(
|
442
|
+
|
583
|
-
|
443
|
+
parent: AdapterView<*>,
|
584
|
-
|
444
|
+
|
585
|
-
|
445
|
+
view: View, position: Int, id: Long
|
446
|
+
|
586
|
-
|
447
|
+
) {
|
448
|
+
|
587
|
-
val spinner
|
449
|
+
val spinner = parent as Spinner
|
588
|
-
|
450
|
+
|
589
|
-
val item = spinner
|
451
|
+
val item = spinner.selectedItem as String
|
590
|
-
|
591
|
-
// Kotlin Android Extensions
|
592
452
|
|
593
453
|
textView.text = item
|
594
454
|
|
595
455
|
}
|
596
456
|
|
597
|
-
|
598
|
-
|
599
|
-
// アイテムが選択されなかった
|
600
|
-
|
601
|
-
override fun onNothingSelected(parent: AdapterView<*>?) {
|
602
|
-
|
603
|
-
//
|
604
|
-
|
605
|
-
}
|
606
|
-
|
607
|
-
```
|
457
|
+
```
|
608
|
-
|
458
|
+
|
609
|
-
の
|
459
|
+
の`item`から取ってきたいのですが、方法がわからない状態です。
|
460
|
+
|
461
|
+
|
610
462
|
|
611
463
|
|
612
464
|
|
613
465
|
### 補足情報(FW/ツールのバージョンなど)
|
614
466
|
|
615
|
-
|
616
|
-
|
617
|
-
|
467
|
+
Android Studio 3.5.3
|