質問編集履歴

2

書き換え

2015/10/13 09:09

投稿

YonamineTK
YonamineTK

スコア42

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,232 @@
18
18
 
19
19
 
20
20
 
21
+ ---------------------------------------------------------------------------------------------------------
22
+
23
+
24
+
25
+ import android.app.Activity;
26
+
27
+ import android.os.Bundle;
28
+
29
+ import android.view.View;
30
+
31
+ import android.widget.Button;
32
+
33
+ import android.widget.TextView;
34
+
35
+
36
+
37
+
38
+
39
+ public class PurasuAct extends Activity implements View.OnClickListener {
40
+
41
+
42
+
43
+
44
+
45
+ private final int btn0 = 0;
46
+
47
+ private final int btn1 = 1;
48
+
49
+ private final int btn2 = 2;
50
+
51
+ private final int btn3 = 3;
52
+
53
+ private final int btn4 = 4;
54
+
55
+ private final int btn5 = 5;
56
+
57
+ private final int btn6 = 6;
58
+
59
+ private final int btn7 = 7;
60
+
61
+ private final int btn8 = 8;
62
+
63
+ private final int btn9 = 9;
64
+
65
+ private final int clearbtn = 0;
66
+
67
+
68
+
69
+
70
+
71
+ Button mButton[];
72
+
73
+
74
+
75
+ int mId[] = {R.id.btn0, R.id.btn1, R.id.btn2, R.id.btn3,
76
+
77
+ R.id.btn4, R.id.btn5, R.id.btn6, R.id.btn7,
78
+
79
+ R.id.btn8, R.id.btn9, R.id.clearbtn};
80
+
81
+
82
+
83
+
84
+
85
+ TextView mTextView;
86
+
87
+
88
+
89
+ /**
90
+
91
+ * 前の処理
92
+
93
+ */
94
+
95
+ int beforeStatus = 0;
96
+
97
+
98
+
99
+ /**
100
+
101
+ * 合計
102
+
103
+ */
104
+
105
+ int total = 0;
106
+
107
+
108
+
109
+ /**
110
+
111
+ * Called when the activity is first created.
112
+
113
+ */
114
+
115
+ @Override
116
+
117
+ public void onCreate(Bundle savedInstanceState) {
118
+
119
+ super.onCreate(savedInstanceState);
120
+
121
+ setContentView(R.layout.practice);
122
+
123
+
124
+
125
+ // 表示用TextView
126
+
127
+ mTextView = (TextView) findViewById(R.id.text7);
128
+
129
+
130
+
131
+ // Button
132
+
133
+ mButton = new Button[mId.length];
134
+
135
+
136
+
137
+
138
+
139
+ for (int i = 0; i < mId.length; i++) {
140
+
141
+ // buttonを取り込む
142
+
143
+ mButton[i] = (Button) findViewById(mId[i]);
144
+
145
+ // buttonのイベント処理
146
+
147
+ mButton[i].setOnClickListener(this);
148
+
149
+ }
150
+
151
+ }
152
+
153
+
154
+
155
+ @Override
156
+
157
+ public void onClick(View v) {
158
+
159
+
160
+
161
+ TextView text7 = (TextView)findViewById(R.id.text7);
162
+
163
+
164
+
165
+ // 押されたボタンがどのボタンかを判定
166
+
167
+ for (int i = 0; i < mId.length; i++) {
168
+
169
+ if (v.equals(mButton[i])) {
170
+
171
+ // CLEAR
172
+
173
+ if (i == clearbtn) {
174
+
175
+ mTextView.setText("");
176
+
177
+ total = 0;
178
+
179
+ beforeStatus = clearbtn;
180
+
181
+ }
182
+
183
+ // 数字
184
+
185
+ else if (i < 10) {
186
+
187
+ String nowValue = mTextView.getText().toString();
188
+
189
+ nowValue = nowValue + i;
190
+
191
+ mTextView.setText(nowValue);
192
+
193
+ beforeStatus = i;
194
+
195
+ }
196
+
197
+ break;
198
+
199
+ }
200
+
201
+ }
202
+
203
+
204
+
205
+
206
+
207
+ // 入力内容を取得
208
+
209
+ String strNum = mTextView.getText().toString();
210
+
211
+
212
+
213
+
214
+
215
+ // 数値に変換
216
+
217
+ int num = Integer.parseInt(strNum);
218
+
219
+
220
+
221
+
222
+
223
+ // 結果表示用テキストに設定
224
+
225
+ text7.setText(Integer.toString(num));
226
+
227
+
228
+
229
+ text7.setVisibility(View.VISIBLE);
230
+
231
+
232
+
233
+
234
+
235
+ }
236
+
237
+
238
+
239
+ }
240
+
241
+
242
+
243
+
244
+
245
+ ---------------------------------------------------------------------------------------------------------
246
+
21
247
 
22
248
 
23
249
  開発環境

1

文法の修正

2015/10/13 09:08

投稿

YonamineTK
YonamineTK

スコア42

test CHANGED
File without changes
test CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  現在、添付画像の様なレイアウトで、
6
6
 
7
- 数字ボタンをクリクした際に、画面中央の四角にクリしたボタンの値が
7
+ 例えば、数字ボタン1プすると、画面中央の四角にしたボタンの値である1
8
8
 
9
- 表示されるアプリを作成しているのですが、
9
+ 表示され、ボタン1、ボタン2をタップすと、12と表示されるアプリを作成しているのですが、
10
10
 
11
11
  いまいち、Layoutとclassの結びつけかた等が分かりません。
12
12