質問編集履歴
2
書き換え
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,7 +8,120 @@
|
|
8
8
|
|
9
9
|
よろしくお願い致します。
|
10
10
|
|
11
|
+
---------------------------------------------------------------------------------------------------------
|
11
12
|
|
13
|
+
import android.app.Activity;
|
14
|
+
import android.os.Bundle;
|
15
|
+
import android.view.View;
|
16
|
+
import android.widget.Button;
|
17
|
+
import android.widget.TextView;
|
18
|
+
|
19
|
+
|
20
|
+
public class PurasuAct extends Activity implements View.OnClickListener {
|
21
|
+
|
22
|
+
|
23
|
+
private final int btn0 = 0;
|
24
|
+
private final int btn1 = 1;
|
25
|
+
private final int btn2 = 2;
|
26
|
+
private final int btn3 = 3;
|
27
|
+
private final int btn4 = 4;
|
28
|
+
private final int btn5 = 5;
|
29
|
+
private final int btn6 = 6;
|
30
|
+
private final int btn7 = 7;
|
31
|
+
private final int btn8 = 8;
|
32
|
+
private final int btn9 = 9;
|
33
|
+
private final int clearbtn = 0;
|
34
|
+
|
35
|
+
|
36
|
+
Button mButton[];
|
37
|
+
|
38
|
+
int mId[] = {R.id.btn0, R.id.btn1, R.id.btn2, R.id.btn3,
|
39
|
+
R.id.btn4, R.id.btn5, R.id.btn6, R.id.btn7,
|
40
|
+
R.id.btn8, R.id.btn9, R.id.clearbtn};
|
41
|
+
|
42
|
+
|
43
|
+
TextView mTextView;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* 前の処理
|
47
|
+
*/
|
48
|
+
int beforeStatus = 0;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* 合計
|
52
|
+
*/
|
53
|
+
int total = 0;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Called when the activity is first created.
|
57
|
+
*/
|
58
|
+
@Override
|
59
|
+
public void onCreate(Bundle savedInstanceState) {
|
60
|
+
super.onCreate(savedInstanceState);
|
61
|
+
setContentView(R.layout.practice);
|
62
|
+
|
63
|
+
// 表示用TextView
|
64
|
+
mTextView = (TextView) findViewById(R.id.text7);
|
65
|
+
|
66
|
+
// Button
|
67
|
+
mButton = new Button[mId.length];
|
68
|
+
|
69
|
+
|
70
|
+
for (int i = 0; i < mId.length; i++) {
|
71
|
+
// buttonを取り込む
|
72
|
+
mButton[i] = (Button) findViewById(mId[i]);
|
73
|
+
// buttonのイベント処理
|
74
|
+
mButton[i].setOnClickListener(this);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
@Override
|
79
|
+
public void onClick(View v) {
|
80
|
+
|
81
|
+
TextView text7 = (TextView)findViewById(R.id.text7);
|
82
|
+
|
83
|
+
// 押されたボタンがどのボタンかを判定
|
84
|
+
for (int i = 0; i < mId.length; i++) {
|
85
|
+
if (v.equals(mButton[i])) {
|
86
|
+
// CLEAR
|
87
|
+
if (i == clearbtn) {
|
88
|
+
mTextView.setText("");
|
89
|
+
total = 0;
|
90
|
+
beforeStatus = clearbtn;
|
91
|
+
}
|
92
|
+
// 数字
|
93
|
+
else if (i < 10) {
|
94
|
+
String nowValue = mTextView.getText().toString();
|
95
|
+
nowValue = nowValue + i;
|
96
|
+
mTextView.setText(nowValue);
|
97
|
+
beforeStatus = i;
|
98
|
+
}
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
// 入力内容を取得
|
105
|
+
String strNum = mTextView.getText().toString();
|
106
|
+
|
107
|
+
|
108
|
+
// 数値に変換
|
109
|
+
int num = Integer.parseInt(strNum);
|
110
|
+
|
111
|
+
|
112
|
+
// 結果表示用テキストに設定
|
113
|
+
text7.setText(Integer.toString(num));
|
114
|
+
|
115
|
+
text7.setVisibility(View.VISIBLE);
|
116
|
+
|
117
|
+
|
118
|
+
}
|
119
|
+
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
---------------------------------------------------------------------------------------------------------
|
124
|
+
|
12
125
|
開発環境
|
13
126
|
AndroidStudio1.2.2
|
14
127
|
実機:xperiaZL2 Android4.4.2
|
1
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
アプリ開発初心者
|
2
2
|
|
3
3
|
現在、添付画像の様なレイアウトで、
|
4
|
-
数字ボタンを
|
4
|
+
例えば、数字ボタン1をタップすると、画面中央の四角にタップしたボタンの値である1が
|
5
|
-
表示されるアプリを作成しているのですが、
|
5
|
+
表示され、ボタン1、ボタン2をタップすると、12と表示されるアプリを作成しているのですが、
|
6
6
|
いまいち、Layoutとclassの結びつけかた等が分かりません。
|
7
7
|
よろしければ、このようなアプリのsampleを教えて下さい。
|
8
8
|
|