@Kubson
-24 / 2 / 0
Регистрация: 17.07.2014
Сообщений: 253
|
03.08.2015, 12:09
[ТС]
|
|
Лови!
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| public void onClick(View v) {
Button btn1 = new Button (this);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.gang);
Toast toast = Toast.makeText(MainActivity.this, "Вы не ввели необходимые данные.", Toast.LENGTH_SHORT);
final Button button = (Button) findViewById(R.id.button);
final Button button2 = (Button) findViewById(R.id.button2);
final Button button3 = (Button) findViewById(R.id.button3);
double p;
TextView off;
off = (TextView) findViewById(R.id.textView4);
EditText weight = (EditText) findViewById(R.id.editText);
EditText gain = (EditText) findViewById(R.id.editText2);
if (weight.getText().length() == 0) {
toast.show();
button.setEnabled(false);
button2.setEnabled(false);
button3.setEnabled(false); }
else {
if (gain.getText().length() == 0) {
toast.show();
button.setEnabled(false);
button2.setEnabled(false);
button3.setEnabled(false);
}
else {
float w = Float.parseFloat(weight.getText().toString());
float g = Float.parseFloat(gain.getText().toString());
switch (v.getId()){
case R.id.button2:
p = w * g * 0.00482;
p = (int)( p * 100 + 0.5) / 100.;
off.setText(" " + p+" евро"); break;
case R.id.button:
p = w * g * 0.00406;
p = (int)( p * 100 + 0.5) / 100.;
off.setText(" " + p+" евро"); break;
case R.id.button3:
p = w * g * 0.00737;
p = (int)( p * 100 + 0.5) / 100.;
off.setText(" " + p+" евро"); break;
case R.id.button4:
weight.setText("");
gain.setText("");
off.setText("");
break;
case R.id.button5:
if (off.getText().length() == 0) toast.show();
else {
rl = null;
rl.removeAllViews();
rl.addView(btn1, Gravity.LEFT);
}
}
}
}
} |
|
0
|