teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

画像差し替え

2020/09/22 12:46

投稿

KIRIN3
KIRIN3

スコア28

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  そこで以下のようにアクションボタンを画面いっぱいに広げたいのですが、[サンプル](https://developer.android.com/guide/topics/ui/dialogs?hl=ja#AddingButtons)のように作成してもうまくいきません。
8
8
  独自にxmlを作成する以外に方法はないのでしょうか?
9
9
 
10
- ![![イメージ説明](bb96e52100c43535ab70325a7e745ebf.png)](e8742ddbdbee970725d22ecccc2623ce.png)
10
+ ![イメージ説明](4443767ca0fbe3537791fbedf602c1c5.png)
11
11
 
12
12
  ■サンプルを元に作成したソース
13
13
  ```Kotlin

1

追記

2020/09/22 12:46

投稿

KIRIN3
KIRIN3

スコア28

title CHANGED
File without changes
body CHANGED
@@ -7,4 +7,44 @@
7
7
  そこで以下のようにアクションボタンを画面いっぱいに広げたいのですが、[サンプル](https://developer.android.com/guide/topics/ui/dialogs?hl=ja#AddingButtons)のように作成してもうまくいきません。
8
8
  独自にxmlを作成する以外に方法はないのでしょうか?
9
9
 
10
- ![![イメージ説明](bb96e52100c43535ab70325a7e745ebf.png)](e8742ddbdbee970725d22ecccc2623ce.png)
10
+ ![![イメージ説明](bb96e52100c43535ab70325a7e745ebf.png)](e8742ddbdbee970725d22ecccc2623ce.png)
11
+
12
+ ■サンプルを元に作成したソース
13
+ ```Kotlin
14
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
15
+ return activity?.let {
16
+ val selectedItems = ArrayList<Int>() // Where we track the selected items
17
+ val builder = AlertDialog.Builder(it)
18
+ // Set the dialog title
19
+ builder.setTitle(R.string.title_home)
20
+ // Specify the list array, the items to be selected by default (null for none),
21
+ // and the listener through which to receive callbacks when items are selected
22
+ .setMultiChoiceItems(arrayOf("りんご", "みかん", "ぶどう"), null,
23
+ DialogInterface.OnMultiChoiceClickListener { dialog, which, isChecked ->
24
+ if (isChecked) {
25
+ // If the user checked the item, add it to the selected items
26
+ selectedItems.add(which)
27
+ } else if (selectedItems.contains(which)) {
28
+ // Else, if the item is already in the array, remove it
29
+ selectedItems.remove(Integer.valueOf(which))
30
+ }
31
+ })
32
+ // Set the action buttons
33
+ .setPositiveButton(R.string.ok,
34
+ DialogInterface.OnClickListener { dialog, id ->
35
+ // User clicked OK, so save the selectedItems results somewhere
36
+ // or return them to the component that opened the dialog
37
+
38
+ })
39
+ .setNegativeButton(R.string.ng,
40
+ DialogInterface.OnClickListener { dialog, id ->
41
+
42
+ })
43
+
44
+ builder.create()
45
+ } ?: throw IllegalStateException("Activity cannot be null")
46
+ }
47
+ ```
48
+
49
+ ■結果
50
+ ![イメージ説明](3ba242f1862ce099fef44baff6204e71.png)