質問編集履歴
1
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
import android.os.Bundle
|
6
6
|
|
7
7
|
import android.view.View
|
8
|
+
|
9
|
+
import android.widget.TextView
|
8
10
|
|
9
11
|
import android.widget.Toast
|
10
12
|
|
@@ -18,46 +20,158 @@
|
|
18
20
|
|
19
21
|
setContentView(R.layout.activity_main)
|
20
22
|
|
21
|
-
|
23
|
+
val randomNumber = (0..2).random()
|
22
24
|
|
23
25
|
|
24
|
-
|
25
|
-
fun main() {
|
26
|
-
|
27
|
-
val rondomNumber = (0..2).random()
|
28
26
|
|
29
27
|
}
|
30
28
|
|
31
29
|
|
32
30
|
|
33
|
-
|
34
|
-
|
35
31
|
fun showMessage(view: View) {
|
36
32
|
|
37
|
-
if (view.id ==
|
33
|
+
if (view.id == random || view.id == random ){
|
34
|
+
|
35
|
+
//
|
38
36
|
|
39
37
|
Toast.makeText(this, "正解!", Toast.LENGTH_LONG).show()
|
40
38
|
|
41
|
-
}
|
39
|
+
}else if (view.id == random + 1) {
|
42
40
|
|
43
|
-
|
41
|
+
//はずれ
|
44
42
|
|
45
|
-
|
43
|
+
Toast.makeText(this, "はずれ!正解は1", Toast.LENGTH_LONG).show()
|
46
44
|
|
47
|
-
|
45
|
+
}else if (view.id == random + 2){
|
48
46
|
|
49
|
-
|
47
|
+
//はずれ
|
48
|
+
|
49
|
+
Toast.makeText(this, "はずれ!正解は3", Toast.LENGTH_LONG).show()
|
50
|
+
|
51
|
+
|
50
52
|
|
51
53
|
}
|
52
54
|
|
53
55
|
}
|
54
56
|
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
レイアウトのコードです
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<?xml version="1.0" encoding="utf-8"?>
|
70
|
+
|
71
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
72
|
+
|
73
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
74
|
+
|
75
|
+
xmlns:tools="http://schemas.android.com/tools"
|
76
|
+
|
77
|
+
android:layout_width="match_parent"
|
78
|
+
|
79
|
+
android:layout_height="match_parent"
|
80
|
+
|
81
|
+
tools:context=".MainActivity">
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<TextView
|
86
|
+
|
87
|
+
android:id="@+id/textView"
|
88
|
+
|
89
|
+
android:layout_width="wrap_content"
|
90
|
+
|
91
|
+
android:layout_height="wrap_content"
|
92
|
+
|
93
|
+
android:text="1から3のどれかを押す"
|
94
|
+
|
95
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
96
|
+
|
97
|
+
app:layout_constraintLeft_toLeftOf="parent"
|
98
|
+
|
99
|
+
app:layout_constraintRight_toRightOf="parent"
|
100
|
+
|
101
|
+
app:layout_constraintTop_toTopOf="parent" />
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<Button
|
106
|
+
|
107
|
+
android:id="@+id/button"
|
108
|
+
|
109
|
+
android:layout_width="wrap_content"
|
110
|
+
|
111
|
+
android:layout_height="wrap_content"
|
112
|
+
|
113
|
+
android:onClick="showMessage"
|
114
|
+
|
115
|
+
android:text="2"
|
116
|
+
|
117
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
118
|
+
|
119
|
+
app:layout_constraintEnd_toEndOf="parent"
|
120
|
+
|
121
|
+
app:layout_constraintStart_toStartOf="parent"
|
122
|
+
|
123
|
+
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
<Button
|
128
|
+
|
129
|
+
android:id="@+id/button2"
|
130
|
+
|
131
|
+
android:layout_width="wrap_content"
|
132
|
+
|
133
|
+
android:layout_height="wrap_content"
|
134
|
+
|
135
|
+
android:onClick="showMessage"
|
136
|
+
|
137
|
+
android:text="1"
|
138
|
+
|
139
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
140
|
+
|
141
|
+
app:layout_constraintEnd_toStartOf="@+id/button"
|
142
|
+
|
143
|
+
app:layout_constraintStart_toStartOf="parent"
|
144
|
+
|
145
|
+
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
<Button
|
150
|
+
|
151
|
+
android:id="@+id/button3"
|
152
|
+
|
153
|
+
android:layout_width="wrap_content"
|
154
|
+
|
155
|
+
android:layout_height="wrap_content"
|
156
|
+
|
157
|
+
android:onClick="showMessage"
|
158
|
+
|
159
|
+
android:text="3"
|
160
|
+
|
161
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
162
|
+
|
163
|
+
app:layout_constraintEnd_toEndOf="parent"
|
164
|
+
|
165
|
+
app:layout_constraintStart_toEndOf="@+id/button"
|
166
|
+
|
167
|
+
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
168
|
+
|
169
|
+
|
170
|
+
|
55
171
|
|
56
172
|
|
57
173
|
### ヘディングのテキスト
|
58
174
|
|
59
|
-
|
175
|
+
1、2、3のボタンを押したときにランダムで正解かハズレを表示させたいです。
|
60
176
|
|
61
|
-
|
177
|
+
randomNumberの使い方と表示の仕方がわかりません。
|
62
|
-
|
63
|
-
ボタン1、2、3を押したら正解!はずれ!正解は〜ですと表示させたいです。
|