質問編集履歴
6
エラーについて追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -372,7 +372,7 @@
|
|
372
372
|
|
373
373
|
|
374
374
|
|
375
|
-
######AppInfo.kt
|
375
|
+
######AppInfo.kt//エラーをコードの中にメモしています
|
376
376
|
|
377
377
|
|
378
378
|
|
@@ -478,7 +478,7 @@
|
|
478
478
|
|
479
479
|
|
480
480
|
|
481
|
-
######ReleaseScreen.kt追加
|
481
|
+
######ReleaseScreen.kt追加 エラーなし
|
482
482
|
|
483
483
|
|
484
484
|
|
@@ -548,7 +548,7 @@
|
|
548
548
|
|
549
549
|
|
550
550
|
|
551
|
-
######LauncherActivity.kt
|
551
|
+
######LauncherActivity.kt//エラーをコードの中にメモしています
|
552
552
|
|
553
553
|
```Kotlin
|
554
554
|
|
5
コードに言語タグ付け足し
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,73 +50,493 @@
|
|
50
50
|
|
51
51
|
######AppAdapter.kt
|
52
52
|
|
53
|
+
```Kotlin
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
package com.example....
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
import android.view.LayoutInflater
|
62
|
+
|
63
|
+
import android.view.View
|
64
|
+
|
65
|
+
import android.view.ViewGroup
|
66
|
+
|
67
|
+
import android.widget.ImageView
|
68
|
+
|
69
|
+
import android.widget.TextView
|
70
|
+
|
71
|
+
import androidx.recyclerview.widget.RecyclerView
|
72
|
+
|
73
|
+
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
class AppAdapter(
|
78
|
+
|
79
|
+
private val inflater: LayoutInflater,
|
80
|
+
|
81
|
+
private val list: List<AppInfo>,
|
82
|
+
|
83
|
+
private val onClick: (view: View, info: AppInfo) -> Unit
|
84
|
+
|
85
|
+
) : RecyclerView.Adapter<AppAdapter.AppViewHolder>() {
|
86
|
+
|
87
|
+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder =
|
88
|
+
|
89
|
+
AppViewHolder(inflater.inflate(R.layout.li_application, parent, false))
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
override fun getItemCount(): Int = list.size
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
98
|
+
|
99
|
+
val info = list[position]
|
100
|
+
|
101
|
+
holder.itemView.setOnClickListener { onClick(it, info) }
|
102
|
+
|
103
|
+
holder.icon.setImageDrawable(info.icon)
|
104
|
+
|
105
|
+
holder.label.text = info.label
|
106
|
+
|
107
|
+
holder.packageName.text = info.componentName.packageName
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
class AppViewHolder(itemView: View) : ViewHolder(itemView) {
|
114
|
+
|
115
|
+
val icon: ImageView = itemView.findViewById(R.id.icon)
|
116
|
+
|
117
|
+
val label: TextView = itemView.findViewById(R.id.label)
|
118
|
+
|
119
|
+
val packageName: TextView = itemView.findViewById(R.id.packageName)
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
53
125
|
```
|
54
126
|
|
55
127
|
|
56
128
|
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
######AppInfo.kt
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
```Kotlin
|
140
|
+
|
57
|
-
package com.example.
|
141
|
+
package com.example....
|
142
|
+
|
143
|
+
|
144
|
+
|
58
|
-
|
145
|
+
import android.content.ActivityNotFoundException
|
146
|
+
|
59
|
-
|
147
|
+
import android.content.ComponentName
|
148
|
+
|
60
|
-
|
149
|
+
import android.content.Context
|
150
|
+
|
151
|
+
import android.content.Intent
|
152
|
+
|
153
|
+
import android.graphics.drawable.Drawable
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
data class AppInfo(
|
158
|
+
|
159
|
+
val icon: Drawable,
|
160
|
+
|
161
|
+
val label: String,
|
162
|
+
|
163
|
+
val componentName: ComponentName
|
164
|
+
|
165
|
+
) {
|
166
|
+
|
167
|
+
fun launch(context: Context) {
|
168
|
+
|
169
|
+
try {
|
170
|
+
|
171
|
+
val intent = Intent(Intent.ACTION_MAIN).also {
|
172
|
+
|
173
|
+
it.flags = Intent.FLAG_ACTIVITY_NEW_TASK or
|
174
|
+
|
175
|
+
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
176
|
+
|
177
|
+
it.addCategory(Intent.CATEGORY_LAUNCHER)
|
178
|
+
|
179
|
+
it.component = componentName
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
context.startActivity(intent)
|
184
|
+
|
185
|
+
} catch (e: ActivityNotFoundException) {
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
```
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
######AppInfoList.kt
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
```Kotlin
|
204
|
+
|
205
|
+
package com.example....
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
import android.content.ComponentName
|
210
|
+
|
211
|
+
import android.content.Context
|
212
|
+
|
213
|
+
import android.content.Intent
|
214
|
+
|
215
|
+
import android.content.pm.PackageManager
|
216
|
+
|
217
|
+
import android.graphics.drawable.Drawable
|
218
|
+
|
219
|
+
import android.os.Build
|
220
|
+
|
221
|
+
import androidx.annotation.RequiresApi
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
object AppInfoList{
|
226
|
+
|
227
|
+
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
228
|
+
|
229
|
+
fun create(context: Context): List<AppInfo> {
|
230
|
+
|
231
|
+
val pm = context.packageManager
|
232
|
+
|
233
|
+
val intent = Intent(Intent.ACTION_MAIN)
|
234
|
+
|
235
|
+
.also { it.addCategory(Intent.CATEGORY_LAUNCHER) }
|
236
|
+
|
237
|
+
return pm.queryIntentActivities(intent, PackageManager.MATCH_ALL)
|
238
|
+
|
239
|
+
.asSequence()
|
240
|
+
|
241
|
+
.mapNotNull { it.activityInfo }
|
242
|
+
|
243
|
+
.filter { it.packageName != context.packageName }
|
244
|
+
|
245
|
+
.map {
|
246
|
+
|
247
|
+
AppInfo(
|
248
|
+
|
249
|
+
it.loadIcon(pm) ?: getDefaultIcon(context),
|
250
|
+
|
251
|
+
it.loadLabel(pm).toString(),
|
252
|
+
|
253
|
+
ComponentName(it.packageName, it.name)
|
254
|
+
|
255
|
+
)
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
.sortedBy { it.label }
|
260
|
+
|
261
|
+
.toList()
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
266
|
+
|
267
|
+
private fun getDefaultIcon(context: Context): Drawable {
|
268
|
+
|
269
|
+
return context.resources.getDrawable(R.mipmap.ic_launcher, null)
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
```
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
######LauncherActivity.kt
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
```Kotlin
|
292
|
+
|
293
|
+
package com.example....
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
import android.os.Build
|
298
|
+
|
299
|
+
import androidx.appcompat.app.AppCompatActivity
|
300
|
+
|
61
|
-
import android.
|
301
|
+
import android.os.Bundle
|
302
|
+
|
303
|
+
import androidx.annotation.RequiresApi
|
304
|
+
|
305
|
+
import androidx.recyclerview.widget.LinearLayoutManager
|
306
|
+
|
307
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
class LauncherActivity : AppCompatActivity() {
|
312
|
+
|
313
|
+
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
314
|
+
|
315
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
316
|
+
|
317
|
+
super.onCreate(savedInstanceState)
|
318
|
+
|
319
|
+
setContentView(R.layout.activity_main)
|
320
|
+
|
321
|
+
val adapter = AppAdapter(layoutInflater, AppInfoList.create(this)) { view, info ->
|
322
|
+
|
323
|
+
info.launch(this)}
|
324
|
+
|
325
|
+
recyclerView.adapter = adapter
|
326
|
+
|
327
|
+
recyclerView.layoutManager = LinearLayoutManager(this)
|
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
|
+
## 試したこと
|
360
|
+
|
361
|
+
0. 画面②のActivityとlayoutを追加した
|
362
|
+
|
363
|
+
0. 書籍でRecyclerViewについて調べた。
|
364
|
+
|
365
|
+
[Androidアプリ開発の教科書 Kotlin対応](https://ebookstore.sony.jp/item/LT000118015000950817/)
|
366
|
+
|
367
|
+
0. AppInfo.ktのTry-Catch構文のtryでLaunchという関数が使われていたため、その関数が他のアプリを起動するためのコードだと考えた。よってその部分を画面②へ遷移するためのコードに修正した。
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
######AppInfo.kt(エラー発生)
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
```Kotlin
|
380
|
+
|
381
|
+
package com.example....
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
import android.content.ActivityNotFoundException
|
386
|
+
|
387
|
+
import android.content.ComponentName
|
388
|
+
|
389
|
+
import android.content.Context
|
390
|
+
|
391
|
+
import android.content.Intent
|
392
|
+
|
393
|
+
import android.graphics.drawable.Drawable
|
62
394
|
|
63
395
|
import android.view.View
|
64
396
|
|
397
|
+
import androidx.core.content.ContextCompat.startActivity
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
data class AppInfo(
|
402
|
+
|
403
|
+
val icon: Drawable,
|
404
|
+
|
405
|
+
val label: String,
|
406
|
+
|
407
|
+
val componentName: ComponentName
|
408
|
+
|
409
|
+
) {
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
private inner class ItemClickListener : View.OnClickListener{
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
//Unit defined in android.view.View.OnClickListener
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
fun launch(context: Context) {
|
422
|
+
|
423
|
+
try {
|
424
|
+
|
425
|
+
override fun onClick(view: View){
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
//Modifier 'override' is not applicable to 'local function'
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
val appNames = label.text.toString()
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
//Unresolved reference: text
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
val intent = Intent(applicationContext, ReleaseScreen::class.java)
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
//Unresolved reference: applicationContext
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
intent.putExtra("appNames", appNames)
|
450
|
+
|
451
|
+
startActivity(intent)
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
//Type mismatch: inferred type is Intent but Context was expected
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
} catch (e: ActivityNotFoundException) {
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
}
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
```
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
######ReleaseScreen.kt追加
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
```Kotlin
|
486
|
+
|
487
|
+
package com.example....
|
488
|
+
|
489
|
+
|
490
|
+
|
65
|
-
import android.
|
491
|
+
import android.os.Bundle
|
66
|
-
|
67
|
-
import android.widget.ImageView
|
68
492
|
|
69
493
|
import android.widget.TextView
|
70
494
|
|
71
|
-
import androidx.
|
495
|
+
import androidx.appcompat.app.AppCompatActivity
|
72
|
-
|
496
|
+
|
73
|
-
import android
|
497
|
+
import kotlinx.android.synthetic.main.activity_release_screen.*
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
498
|
+
|
78
|
-
|
79
|
-
|
499
|
+
|
80
|
-
|
81
|
-
|
500
|
+
|
82
|
-
|
83
|
-
private val onClick: (view: View, info: AppInfo) -> Unit
|
84
|
-
|
85
|
-
|
501
|
+
class ReleaseScreen : AppCompatActivity() {
|
86
|
-
|
87
|
-
|
502
|
+
|
88
|
-
|
89
|
-
AppViewHolder(inflater.inflate(R.layout.li_application, parent, false))
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
override fun
|
503
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
504
|
+
|
98
|
-
|
99
|
-
val info = list[position]
|
100
|
-
|
101
|
-
holder.itemView.setOnClickListener { onClick(it, info) }
|
102
|
-
|
103
|
-
|
505
|
+
super.onCreate(savedInstanceState)
|
506
|
+
|
104
|
-
|
507
|
+
setContentView(R.layout.activity_release_screen)
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
val appNames = intent.getStringExtra("appNames")
|
514
|
+
|
515
|
+
val installed = findViewById<TextView>(R.id.installed)
|
516
|
+
|
517
|
+
|
518
|
+
|
105
|
-
|
519
|
+
installed.text = appNames
|
520
|
+
|
521
|
+
|
522
|
+
|
106
|
-
|
523
|
+
n0.minValue = 0
|
524
|
+
|
107
|
-
|
525
|
+
n0.maxValue = 24
|
108
|
-
|
109
|
-
|
526
|
+
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
527
|
+
n0.value = 0
|
114
|
-
|
528
|
+
|
115
|
-
|
529
|
+
n1.minValue = 0
|
116
|
-
|
530
|
+
|
117
|
-
|
531
|
+
n1.maxValue = 5
|
532
|
+
|
118
|
-
|
533
|
+
n1.value = 0
|
534
|
+
|
119
|
-
|
535
|
+
n2.minValue = 0
|
536
|
+
|
537
|
+
n2.maxValue = 9
|
538
|
+
|
539
|
+
n2.value = 0
|
120
540
|
|
121
541
|
}
|
122
542
|
|
@@ -126,59 +546,71 @@
|
|
126
546
|
|
127
547
|
|
128
548
|
|
549
|
+
|
550
|
+
|
129
|
-
######A
|
551
|
+
######LauncherActivity.kt(修正はしていないがエラー発生)
|
552
|
+
|
130
|
-
|
553
|
+
```Kotlin
|
131
|
-
|
132
|
-
|
554
|
+
|
133
|
-
|
555
|
+
package com.example....
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
556
|
+
|
138
|
-
|
139
|
-
|
557
|
+
|
140
|
-
|
141
|
-
import android.content.Context
|
142
558
|
|
143
559
|
import android.content.Intent
|
144
560
|
|
561
|
+
import android.os.Build
|
562
|
+
|
563
|
+
import androidx.appcompat.app.AppCompatActivity
|
564
|
+
|
565
|
+
import android.os.Bundle
|
566
|
+
|
567
|
+
import android.view.View
|
568
|
+
|
145
|
-
import android.g
|
569
|
+
import android.widget.AdapterView
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
570
|
+
|
150
|
-
|
151
|
-
val icon: Drawable,
|
152
|
-
|
153
|
-
val label: String,
|
154
|
-
|
155
|
-
|
571
|
+
import android.widget.TextView
|
156
|
-
|
572
|
+
|
157
|
-
|
573
|
+
import androidx.annotation.RequiresApi
|
574
|
+
|
158
|
-
|
575
|
+
import androidx.core.content.ContextCompat.startActivity
|
576
|
+
|
577
|
+
import androidx.recyclerview.widget.LinearLayoutManager
|
578
|
+
|
579
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
580
|
+
|
581
|
+
import kotlinx.android.synthetic.main.li_application.*
|
582
|
+
|
583
|
+
|
584
|
+
|
159
|
-
|
585
|
+
class LauncherActivity : AppCompatActivity() {
|
160
|
-
|
586
|
+
|
161
|
-
|
587
|
+
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
162
|
-
|
588
|
+
|
163
|
-
|
589
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
164
|
-
|
165
|
-
|
590
|
+
|
166
|
-
|
167
|
-
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
168
|
-
|
169
|
-
it.addCategory(Intent.CATEGORY_LAUNCHER)
|
170
|
-
|
171
|
-
|
591
|
+
super.onCreate(savedInstanceState)
|
592
|
+
|
172
|
-
|
593
|
+
setContentView(R.layout.activity_main)
|
594
|
+
|
595
|
+
val adapter = AppAdapter(layoutInflater, AppInfoList.create(this)) { view, info ->
|
596
|
+
|
597
|
+
info.launch(this)}
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
//Unresolved reference: launch
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
recyclerView.adapter = adapter
|
606
|
+
|
607
|
+
recyclerView.layoutManager = LinearLayoutManager(this)
|
608
|
+
|
173
|
-
|
609
|
+
}
|
174
|
-
|
175
|
-
|
610
|
+
|
176
|
-
|
177
|
-
|
611
|
+
|
178
|
-
|
179
|
-
|
612
|
+
|
180
|
-
|
181
|
-
|
613
|
+
|
182
614
|
|
183
615
|
}
|
184
616
|
|
@@ -188,422 +620,6 @@
|
|
188
620
|
|
189
621
|
|
190
622
|
|
191
|
-
######AppInfoList.kt
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
```package com.example.yorimiti_block1
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
import android.content.ComponentName
|
200
|
-
|
201
|
-
import android.content.Context
|
202
|
-
|
203
|
-
import android.content.Intent
|
204
|
-
|
205
|
-
import android.content.pm.PackageManager
|
206
|
-
|
207
|
-
import android.graphics.drawable.Drawable
|
208
|
-
|
209
|
-
import android.os.Build
|
210
|
-
|
211
|
-
import androidx.annotation.RequiresApi
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
object AppInfoList{
|
216
|
-
|
217
|
-
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
218
|
-
|
219
|
-
fun create(context: Context): List<AppInfo> {
|
220
|
-
|
221
|
-
val pm = context.packageManager
|
222
|
-
|
223
|
-
val intent = Intent(Intent.ACTION_MAIN)
|
224
|
-
|
225
|
-
.also { it.addCategory(Intent.CATEGORY_LAUNCHER) }
|
226
|
-
|
227
|
-
return pm.queryIntentActivities(intent, PackageManager.MATCH_ALL)
|
228
|
-
|
229
|
-
.asSequence()
|
230
|
-
|
231
|
-
.mapNotNull { it.activityInfo }
|
232
|
-
|
233
|
-
.filter { it.packageName != context.packageName }
|
234
|
-
|
235
|
-
.map {
|
236
|
-
|
237
|
-
AppInfo(
|
238
|
-
|
239
|
-
it.loadIcon(pm) ?: getDefaultIcon(context),
|
240
|
-
|
241
|
-
it.loadLabel(pm).toString(),
|
242
|
-
|
243
|
-
ComponentName(it.packageName, it.name)
|
244
|
-
|
245
|
-
)
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
.sortedBy { it.label }
|
250
|
-
|
251
|
-
.toList()
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
256
|
-
|
257
|
-
private fun getDefaultIcon(context: Context): Drawable {
|
258
|
-
|
259
|
-
return context.resources.getDrawable(R.mipmap.ic_launcher, null)
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
}
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
```
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
######LauncherActivity.kt
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
```package com.example.yorimiti_block1
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
import android.os.Build
|
286
|
-
|
287
|
-
import androidx.appcompat.app.AppCompatActivity
|
288
|
-
|
289
|
-
import android.os.Bundle
|
290
|
-
|
291
|
-
import androidx.annotation.RequiresApi
|
292
|
-
|
293
|
-
import androidx.recyclerview.widget.LinearLayoutManager
|
294
|
-
|
295
|
-
import kotlinx.android.synthetic.main.activity_main.*
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
class LauncherActivity : AppCompatActivity() {
|
300
|
-
|
301
|
-
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
302
|
-
|
303
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
304
|
-
|
305
|
-
super.onCreate(savedInstanceState)
|
306
|
-
|
307
|
-
setContentView(R.layout.activity_main)
|
308
|
-
|
309
|
-
val adapter = AppAdapter(layoutInflater, AppInfoList.create(this)) { view, info ->
|
310
|
-
|
311
|
-
info.launch(this)}
|
312
|
-
|
313
|
-
recyclerView.adapter = adapter
|
314
|
-
|
315
|
-
recyclerView.layoutManager = LinearLayoutManager(this)
|
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
|
-
0. 画面②のActivityとlayoutを追加した
|
350
|
-
|
351
|
-
0. 書籍でRecyclerViewについて調べた。
|
352
|
-
|
353
|
-
[Androidアプリ開発の教科書 Kotlin対応](https://ebookstore.sony.jp/item/LT000118015000950817/)
|
354
|
-
|
355
|
-
0. AppInfo.ktのTry-Catch構文のtryでLaunchという関数が使われていたため、その関数が他のアプリを起動するためのコードだと考えた。よってその部分を画面②へ遷移するためのコードに修正した。
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
######AppInfo.kt(エラー発生)
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
```
|
368
|
-
|
369
|
-
package com.example.yorimiti_block1
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
import android.content.ActivityNotFoundException
|
374
|
-
|
375
|
-
import android.content.ComponentName
|
376
|
-
|
377
|
-
import android.content.Context
|
378
|
-
|
379
|
-
import android.content.Intent
|
380
|
-
|
381
|
-
import android.graphics.drawable.Drawable
|
382
|
-
|
383
|
-
import android.view.View
|
384
|
-
|
385
|
-
import androidx.core.content.ContextCompat.startActivity
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
data class AppInfo(
|
390
|
-
|
391
|
-
val icon: Drawable,
|
392
|
-
|
393
|
-
val label: String,
|
394
|
-
|
395
|
-
val componentName: ComponentName
|
396
|
-
|
397
|
-
) {
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
private inner class ItemClickListener : View.OnClickListener{
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
//Unit defined in android.view.View.OnClickListener
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
fun launch(context: Context) {
|
410
|
-
|
411
|
-
try {
|
412
|
-
|
413
|
-
override fun onClick(view: View){
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
//Modifier 'override' is not applicable to 'local function'
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
val appNames = label.text.toString()
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
//Unresolved reference: text
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
val intent = Intent(applicationContext, ReleaseScreen::class.java)
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
//Unresolved reference: applicationContext
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
intent.putExtra("appNames", appNames)
|
438
|
-
|
439
|
-
startActivity(intent)
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
//Type mismatch: inferred type is Intent but Context was expected
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
}
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
} catch (e: ActivityNotFoundException) {
|
452
|
-
|
453
|
-
}
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
}
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
```
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
######ReleaseScreen.kt追加
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
```package com.example.yorimiti_block1
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
import android.os.Bundle
|
478
|
-
|
479
|
-
import android.widget.TextView
|
480
|
-
|
481
|
-
import androidx.appcompat.app.AppCompatActivity
|
482
|
-
|
483
|
-
import kotlinx.android.synthetic.main.activity_release_screen.*
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
class ReleaseScreen : AppCompatActivity() {
|
488
|
-
|
489
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
490
|
-
|
491
|
-
super.onCreate(savedInstanceState)
|
492
|
-
|
493
|
-
setContentView(R.layout.activity_release_screen)
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
val appNames = intent.getStringExtra("appNames")
|
500
|
-
|
501
|
-
val installed = findViewById<TextView>(R.id.installed)
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
installed.text = appNames
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
n0.minValue = 0
|
510
|
-
|
511
|
-
n0.maxValue = 24
|
512
|
-
|
513
|
-
n0.value = 0
|
514
|
-
|
515
|
-
n1.minValue = 0
|
516
|
-
|
517
|
-
n1.maxValue = 5
|
518
|
-
|
519
|
-
n1.value = 0
|
520
|
-
|
521
|
-
n2.minValue = 0
|
522
|
-
|
523
|
-
n2.maxValue = 9
|
524
|
-
|
525
|
-
n2.value = 0
|
526
|
-
|
527
|
-
}
|
528
|
-
|
529
|
-
}
|
530
|
-
|
531
|
-
```
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
######LauncherActivity.kt(修正はしていないがエラー発生)
|
538
|
-
|
539
|
-
```package com.example.yorimiti_block1
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
import android.content.Intent
|
544
|
-
|
545
|
-
import android.os.Build
|
546
|
-
|
547
|
-
import androidx.appcompat.app.AppCompatActivity
|
548
|
-
|
549
|
-
import android.os.Bundle
|
550
|
-
|
551
|
-
import android.view.View
|
552
|
-
|
553
|
-
import android.widget.AdapterView
|
554
|
-
|
555
|
-
import android.widget.TextView
|
556
|
-
|
557
|
-
import androidx.annotation.RequiresApi
|
558
|
-
|
559
|
-
import androidx.core.content.ContextCompat.startActivity
|
560
|
-
|
561
|
-
import androidx.recyclerview.widget.LinearLayoutManager
|
562
|
-
|
563
|
-
import kotlinx.android.synthetic.main.activity_main.*
|
564
|
-
|
565
|
-
import kotlinx.android.synthetic.main.li_application.*
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
class LauncherActivity : AppCompatActivity() {
|
570
|
-
|
571
|
-
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
572
|
-
|
573
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
574
|
-
|
575
|
-
super.onCreate(savedInstanceState)
|
576
|
-
|
577
|
-
setContentView(R.layout.activity_main)
|
578
|
-
|
579
|
-
val adapter = AppAdapter(layoutInflater, AppInfoList.create(this)) { view, info ->
|
580
|
-
|
581
|
-
info.launch(this)}
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
//Unresolved reference: launch
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
recyclerView.adapter = adapter
|
590
|
-
|
591
|
-
recyclerView.layoutManager = LinearLayoutManager(this)
|
592
|
-
|
593
|
-
}
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
}
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
```
|
604
|
-
|
605
|
-
|
606
|
-
|
607
623
|
|
608
624
|
|
609
625
|
|
4
写真修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
②タップしたアプリの使用時間を選択する画面
|
24
24
|
|
25
|
-
![イメージ説明](3
|
25
|
+
![イメージ説明](7c342e3a187c20bcab490155580d88c6.png)
|
26
26
|
|
27
27
|
↓
|
28
28
|
|
3
写真修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,13 +16,13 @@
|
|
16
16
|
|
17
17
|
①端末にインストール済みアプリのRecyclerView
|
18
18
|
|
19
|
-
![
|
19
|
+
![イメージ説明](7527fb54a89d1c5c50c16943efb12dc4.png)
|
20
20
|
|
21
21
|
↓
|
22
22
|
|
23
23
|
②タップしたアプリの使用時間を選択する画面
|
24
24
|
|
25
|
-
![イメージ説明](b
|
25
|
+
![イメージ説明](387bef3ac3948a245e92db06ff292367.png)
|
26
26
|
|
27
27
|
↓
|
28
28
|
|
2
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Android StudioでRecyclerViewからの画面遷移を実装したい
|
test
CHANGED
File without changes
|
1
前提・実現したいことにスクショを追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
「インストール済みアプリのリスト」→「画面」→「アプリ起動」の画面遷移(アンドロイドアプリ開発)
|
test
CHANGED
@@ -1,28 +1,52 @@
|
|
1
1
|
## 前提・実現したいこと
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
高校の課題研究で、スマホの使い過ぎを防ぐためのアンドロイドアプリの開発をしています。使用言語はKotlinです。
|
6
|
-
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
7
|
-
|
9
|
+
下のような遷移を実装したいです。
|
10
|
+
|
11
|
+
|
12
|
+
|
8
|
-
|
13
|
+
######完成形の遷移
|
14
|
+
|
15
|
+
|
16
|
+
|
9
|
-
|
17
|
+
①端末にインストール済みアプリのRecyclerView
|
18
|
+
|
10
|
-
|
19
|
+
![![](efe0c4b072b8d25ad2043b6c7b790a83.jpeg)
|
20
|
+
|
21
|
+
↓
|
22
|
+
|
11
|
-
|
23
|
+
②タップしたアプリの使用時間を選択する画面
|
24
|
+
|
12
|
-
|
25
|
+
![イメージ説明](b0669d32282a2b6852d0ee6d3b98308e.jpeg)
|
26
|
+
|
27
|
+
↓
|
28
|
+
|
13
|
-
|
29
|
+
③タップしたアプリを起動
|
30
|
+
|
31
|
+
![イメージ説明](c8d08f5001a17a6c53dd99a7830a1a3b.jpeg)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
現在までの工程
|
36
|
+
|
37
|
+
0. 下のサイトの通りにホームアプリを完成させた(①→③の遷移ができた)
|
14
38
|
|
15
39
|
[超シンプルなホームアプリ(ランチャーアプリ)を作る](https://qiita.com/ryo_mm2d/items/00326b0d8f088975fa0e)
|
16
40
|
|
17
|
-
|
18
|
-
|
19
|
-
|
41
|
+
0. 他のアプリを起動する前に②の画面に遷移させるため、修正をしたが、遷移せずエラーも発生した。
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
25
|
-
##実装済みの
|
49
|
+
##工程1で実装済みのホームアプリのコード
|
26
50
|
|
27
51
|
######AppAdapter.kt
|
28
52
|
|
@@ -314,48 +338,6 @@
|
|
314
338
|
|
315
339
|
|
316
340
|
|
317
|
-
######activity_main.xml
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
```<?xml version="1.0" encoding="utf-8"?>
|
322
|
-
|
323
|
-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
324
|
-
|
325
|
-
xmlns:app="http://schemas.android.com/apk/res-auto"
|
326
|
-
|
327
|
-
xmlns:tools="http://schemas.android.com/tools"
|
328
|
-
|
329
|
-
android:layout_width="match_parent"
|
330
|
-
|
331
|
-
android:layout_height="match_parent"
|
332
|
-
|
333
|
-
tools:context=".LauncherActivity">
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
<androidx.recyclerview.widget.RecyclerView
|
338
|
-
|
339
|
-
android:id="@+id/recyclerView"
|
340
|
-
|
341
|
-
android:layout_width="0dp"
|
342
|
-
|
343
|
-
android:layout_height="0dp"
|
344
|
-
|
345
|
-
app:layout_constraintBottom_toBottomOf="parent"
|
346
|
-
|
347
|
-
app:layout_constraintEnd_toEndOf="parent"
|
348
|
-
|
349
|
-
app:layout_constraintStart_toStartOf="parent"
|
350
|
-
|
351
|
-
app:layout_constraintTop_toTopOf="parent" />
|
352
|
-
|
353
|
-
</androidx.constraintlayout.widget.ConstraintLayout>
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
```
|
358
|
-
|
359
341
|
|
360
342
|
|
361
343
|
|
@@ -364,9 +346,21 @@
|
|
364
346
|
|
365
347
|
## 試したこと
|
366
348
|
|
367
|
-
|
349
|
+
0. 画面②のActivityとlayoutを追加した
|
350
|
+
|
368
|
-
|
351
|
+
0. 書籍でRecyclerViewについて調べた。
|
352
|
+
|
353
|
+
[Androidアプリ開発の教科書 Kotlin対応](https://ebookstore.sony.jp/item/LT000118015000950817/)
|
354
|
+
|
355
|
+
0. AppInfo.ktのTry-Catch構文のtryでLaunchという関数が使われていたため、その関数が他のアプリを起動するためのコードだと考えた。よってその部分を画面②へ遷移するためのコードに修正した。
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
369
|
-
######AppInfo.kt
|
363
|
+
######AppInfo.kt(エラー発生)
|
370
364
|
|
371
365
|
|
372
366
|
|
@@ -472,7 +466,7 @@
|
|
472
466
|
|
473
467
|
|
474
468
|
|
475
|
-
######ReleaseScreen.kt
|
469
|
+
######ReleaseScreen.kt追加
|
476
470
|
|
477
471
|
|
478
472
|
|
@@ -540,7 +534,7 @@
|
|
540
534
|
|
541
535
|
|
542
536
|
|
543
|
-
######LauncherActivity.kt
|
537
|
+
######LauncherActivity.kt(修正はしていないがエラー発生)
|
544
538
|
|
545
539
|
```package com.example.yorimiti_block1
|
546
540
|
|
@@ -612,14 +606,12 @@
|
|
612
606
|
|
613
607
|
|
614
608
|
|
615
|
-
これに加えてactivity_release_screen.xmlを追加した。
|
616
|
-
|
617
|
-
|
618
|
-
|
619
609
|
|
620
610
|
|
621
611
|
### 補足情報(FW/ツールのバージョンなど)
|
622
612
|
|
623
613
|
|
624
614
|
|
615
|
+
Windows10
|
616
|
+
|
625
617
|
Android Studio4.0.1
|