質問編集履歴

2

画像差し替え

2020/09/22 12:46

投稿

KIRIN3
KIRIN3

スコア28

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- ![![イメージ説明](bb96e52100c43535ab70325a7e745ebf.png)](e8742ddbdbee970725d22ecccc2623ce.png)
19
+ ![イメージ説明](4443767ca0fbe3537791fbedf602c1c5.png)
20
20
 
21
21
 
22
22
 

1

追記

2020/09/22 12:46

投稿

KIRIN3
KIRIN3

スコア28

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,83 @@
17
17
 
18
18
 
19
19
  ![![イメージ説明](bb96e52100c43535ab70325a7e745ebf.png)](e8742ddbdbee970725d22ecccc2623ce.png)
20
+
21
+
22
+
23
+ ■サンプルを元に作成したソース
24
+
25
+ ```Kotlin
26
+
27
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
28
+
29
+ return activity?.let {
30
+
31
+ val selectedItems = ArrayList<Int>() // Where we track the selected items
32
+
33
+ val builder = AlertDialog.Builder(it)
34
+
35
+ // Set the dialog title
36
+
37
+ builder.setTitle(R.string.title_home)
38
+
39
+ // Specify the list array, the items to be selected by default (null for none),
40
+
41
+ // and the listener through which to receive callbacks when items are selected
42
+
43
+ .setMultiChoiceItems(arrayOf("りんご", "みかん", "ぶどう"), null,
44
+
45
+ DialogInterface.OnMultiChoiceClickListener { dialog, which, isChecked ->
46
+
47
+ if (isChecked) {
48
+
49
+ // If the user checked the item, add it to the selected items
50
+
51
+ selectedItems.add(which)
52
+
53
+ } else if (selectedItems.contains(which)) {
54
+
55
+ // Else, if the item is already in the array, remove it
56
+
57
+ selectedItems.remove(Integer.valueOf(which))
58
+
59
+ }
60
+
61
+ })
62
+
63
+ // Set the action buttons
64
+
65
+ .setPositiveButton(R.string.ok,
66
+
67
+ DialogInterface.OnClickListener { dialog, id ->
68
+
69
+ // User clicked OK, so save the selectedItems results somewhere
70
+
71
+ // or return them to the component that opened the dialog
72
+
73
+
74
+
75
+ })
76
+
77
+ .setNegativeButton(R.string.ng,
78
+
79
+ DialogInterface.OnClickListener { dialog, id ->
80
+
81
+
82
+
83
+ })
84
+
85
+
86
+
87
+ builder.create()
88
+
89
+ } ?: throw IllegalStateException("Activity cannot be null")
90
+
91
+ }
92
+
93
+ ```
94
+
95
+
96
+
97
+ ■結果
98
+
99
+ ![イメージ説明](3ba242f1862ce099fef44baff6204e71.png)