回答編集履歴
2
ボタンアルゴリズムの修正
test
CHANGED
@@ -106,12 +106,90 @@
|
|
106
106
|
|
107
107
|
public void onClick(View v) {
|
108
108
|
|
109
|
+
try {
|
110
|
+
|
111
|
+
final int amount = Integer.parseInt(editText.getText().toString());
|
112
|
+
|
113
|
+
final int number = (int) spinner.getSelectedItem();
|
114
|
+
|
115
|
+
/* 割り勘のアルゴリズムは考えましょう */
|
116
|
+
|
117
|
+
if (amount < 0) {
|
118
|
+
|
119
|
+
managerTextView.setText("負の数は非対応です");
|
120
|
+
|
121
|
+
othersTextView.setText("自然数を入力してください");
|
122
|
+
|
123
|
+
} else {
|
124
|
+
|
125
|
+
final int others = amount / number / 1000 * 1000;
|
126
|
+
|
127
|
+
final int manager = amount - others * (number - 1);
|
128
|
+
|
129
|
+
managerTextView.setText(String.valueOf(manager));
|
130
|
+
|
131
|
+
othersTextView.setText(String.valueOf(others));
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
} catch (NumberFormatException e) {
|
136
|
+
|
137
|
+
managerTextView.setText("parseIntに失敗しました");
|
138
|
+
|
139
|
+
othersTextView.setText("自然数を入力してください");
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
});
|
146
|
+
|
147
|
+
linearLayout.addView(button);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
/* ここまで準備した LinearLayout を表示してあげましょう*/
|
152
|
+
|
153
|
+
setContentView(linearLayout);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
/* xml で記述するのであれば onCreate の中身は↓で十分でしょう
|
160
|
+
|
161
|
+
super.onCreate(savedInstanceState);
|
162
|
+
|
163
|
+
setContentView(R.layout.activity_main);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
final EditText editText = (EditText)findViewById(R.id.editText);
|
168
|
+
|
169
|
+
final Spinner spinner = (Spinner)findViewById(R.id.spinner);
|
170
|
+
|
171
|
+
final TextView managerTextView = (TextView) findViewById(R.id.managerTextView);
|
172
|
+
|
173
|
+
final TextView othersTextView = (TextView) findViewById(R.id.othersTextView);
|
174
|
+
|
175
|
+
final Button button = (Button) findViewById(R.id.button);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, list));
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
button.setOnClickListener(new View.OnClickListener() {
|
184
|
+
|
185
|
+
@Override
|
186
|
+
|
187
|
+
public void onClick(View v) {
|
188
|
+
|
109
189
|
int amount = Integer.parseInt(editText.getText().toString());
|
110
190
|
|
111
191
|
int number = (int) spinner.getSelectedItem();
|
112
192
|
|
113
|
-
/* 割り勘のアルゴリズムは考えましょう */
|
114
|
-
|
115
193
|
managerTextView.setText(String.valueOf(amount / number));
|
116
194
|
|
117
195
|
othersTextView.setText(String.valueOf(amount / number));
|
@@ -120,60 +198,6 @@
|
|
120
198
|
|
121
199
|
});
|
122
200
|
|
123
|
-
linearLayout.addView(button);
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
/* ここまで準備した LinearLayout を表示してあげましょう*/
|
128
|
-
|
129
|
-
setContentView(linearLayout);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
/* xml で記述するのであれば onCreate の中身は↓で十分でしょう
|
136
|
-
|
137
|
-
super.onCreate(savedInstanceState);
|
138
|
-
|
139
|
-
setContentView(R.layout.activity_main);
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
final EditText editText = (EditText)findViewById(R.id.editText);
|
144
|
-
|
145
|
-
final Spinner spinner = (Spinner)findViewById(R.id.spinner);
|
146
|
-
|
147
|
-
final TextView managerTextView = (TextView) findViewById(R.id.managerTextView);
|
148
|
-
|
149
|
-
final TextView othersTextView = (TextView) findViewById(R.id.othersTextView);
|
150
|
-
|
151
|
-
final Button button = (Button) findViewById(R.id.button);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, list));
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
button.setOnClickListener(new View.OnClickListener() {
|
160
|
-
|
161
|
-
@Override
|
162
|
-
|
163
|
-
public void onClick(View v) {
|
164
|
-
|
165
|
-
int amount = Integer.parseInt(editText.getText().toString());
|
166
|
-
|
167
|
-
int number = (int) spinner.getSelectedItem();
|
168
|
-
|
169
|
-
managerTextView.setText(String.valueOf(amount / number));
|
170
|
-
|
171
|
-
othersTextView.setText(String.valueOf(amount / number));
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
});
|
176
|
-
|
177
201
|
*/
|
178
202
|
|
179
203
|
}
|
1
ソースコード修正
test
CHANGED
@@ -148,9 +148,11 @@
|
|
148
148
|
|
149
149
|
final TextView othersTextView = (TextView) findViewById(R.id.othersTextView);
|
150
150
|
|
151
|
+
final Button button = (Button) findViewById(R.id.button);
|
152
|
+
|
151
153
|
|
152
154
|
|
153
|
-
spinner.setAdapter(new ArrayAdapter<>(this, R.layout.s
|
155
|
+
spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, list));
|
154
156
|
|
155
157
|
|
156
158
|
|