回答編集履歴
3
修正しました。
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
public class
|
37
|
+
public class JyankenActivity extends Activity {
|
38
38
|
|
39
39
|
|
40
40
|
|
2
表示の変更
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
```
|
13
|
+
```Java
|
14
14
|
|
15
15
|
package numa.jyanken;
|
16
16
|
|
@@ -120,7 +120,7 @@
|
|
120
120
|
|
121
121
|
|
122
122
|
|
123
|
-
```
|
123
|
+
```XML
|
124
124
|
|
125
125
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
126
126
|
|
1
追記
test
CHANGED
@@ -1,3 +1,185 @@
|
|
1
1
|
少しだけプログラムを変更して動作確認させていただきましたが、普通に動作しました。
|
2
2
|
|
3
3
|
ボタンとテキストの位置が重なってしまっていて見えていないだけということはないですよね?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
またテストに使用したコードは以下ですが、ほとんど変更してません。
|
8
|
+
|
9
|
+
Activityを拡張に変更した点とxmlでRelativeLayoutを使用した以外は何も手を加えておりません。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
package numa.jyanken;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
import android.app.Activity;
|
20
|
+
|
21
|
+
import android.support.v7.app.AppCompatActivity;
|
22
|
+
|
23
|
+
import android.os.Bundle;
|
24
|
+
|
25
|
+
import android.view.View;
|
26
|
+
|
27
|
+
import android.widget.Button;
|
28
|
+
|
29
|
+
import android.widget.TextView;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
import java.util.Random;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
public class MainActivity extends Activity {
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
@Override
|
42
|
+
|
43
|
+
protected void onCreate(Bundle savedInstanceState) {
|
44
|
+
|
45
|
+
super.onCreate(savedInstanceState);
|
46
|
+
|
47
|
+
setContentView(R.layout.jyanken_main);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
final TextView textview = (TextView) findViewById(R.id.editText);
|
52
|
+
|
53
|
+
Button btn = (Button) findViewById(R.id.button);
|
54
|
+
|
55
|
+
btn.setOnClickListener(new View.OnClickListener() {
|
56
|
+
|
57
|
+
@Override
|
58
|
+
|
59
|
+
public void onClick(View v) {
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
int[] player = new int[2];
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
for (int i = 0; i <= 1; i++) {
|
68
|
+
|
69
|
+
Random rnd = new Random();
|
70
|
+
|
71
|
+
int rand = rnd.nextInt(3);
|
72
|
+
|
73
|
+
player[i] = (int) Math.floor(rand);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
if (player[0] - player[1] == 0) {
|
80
|
+
|
81
|
+
textview.setText("引き分け");
|
82
|
+
|
83
|
+
} else if (player[0] - player[1] == -2) {
|
84
|
+
|
85
|
+
textview.setText("負け");
|
86
|
+
|
87
|
+
} else if (player[0] - player[1] == -1) {
|
88
|
+
|
89
|
+
textview.setText("勝ち");
|
90
|
+
|
91
|
+
} else if (player[0] - player[1] == 1) {
|
92
|
+
|
93
|
+
textview.setText("負け");
|
94
|
+
|
95
|
+
} else {
|
96
|
+
|
97
|
+
textview.setText("勝ち");
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
126
|
+
|
127
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
128
|
+
|
129
|
+
xmlns:tools="http://schemas.android.com/tools"
|
130
|
+
|
131
|
+
android:layout_width="match_parent"
|
132
|
+
|
133
|
+
android:layout_height="match_parent"
|
134
|
+
|
135
|
+
tools:context="numa.jyanken.JyankenActivity">
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<Button
|
140
|
+
|
141
|
+
android:id="@+id/button"
|
142
|
+
|
143
|
+
android:layout_width="wrap_content"
|
144
|
+
|
145
|
+
android:layout_height="wrap_content"
|
146
|
+
|
147
|
+
android:onClick="click"
|
148
|
+
|
149
|
+
android:text="Button"
|
150
|
+
|
151
|
+
tools:layout_editor_absoluteX="147dp"
|
152
|
+
|
153
|
+
tools:layout_editor_absoluteY="230dp" />
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
<EditText
|
158
|
+
|
159
|
+
android:id="@+id/editText"
|
160
|
+
|
161
|
+
android:layout_width="wrap_content"
|
162
|
+
|
163
|
+
android:layout_height="wrap_content"
|
164
|
+
|
165
|
+
android:ems="10"
|
166
|
+
|
167
|
+
android:inputType="textPersonName"
|
168
|
+
|
169
|
+
android:text="Name"
|
170
|
+
|
171
|
+
tools:layout_editor_absoluteX="84dp"
|
172
|
+
|
173
|
+
tools:layout_editor_absoluteY="163dp"
|
174
|
+
|
175
|
+
android:layout_below="@+id/button"
|
176
|
+
|
177
|
+
android:layout_toRightOf="@+id/button"
|
178
|
+
|
179
|
+
android:layout_toEndOf="@+id/button"
|
180
|
+
|
181
|
+
android:layout_marginTop="141dp" />
|
182
|
+
|
183
|
+
</RelativeLayout>
|
184
|
+
|
185
|
+
```
|