12.10.2018, 20:16. Показов 5718. Ответов 2
Здравствуйте, дамы и господа!
Помогите пожалуйста разобраться с проблемой.
Я написал для Андроида приложение, которое решает квадратные уравнения. Приложение состоит только из одной Активити. На этой активити есть форма заполнения уравнения и одна кнопка Button, на которой написано "Расчёт". Всё хорошо работает, устанавливается на телефон, запускается, решает уравнения как надо, но есть одна небольшая проблема. Когда я ввожу желаемое уравнение и нажимаю Button "Расчёт", то собственно надпись "Расчёт" с кнопки пропадает и никогда больше не появляется до рестарта приложения. Так происходит и в эмуляторе и на реальном телефоне. Я уже начал думать, что так и задумано разработчиками. Или может есть какой-то параметр для этого? Или это ошибка или недочёт? Текст слова "Расчёт" взят из ресурсов, а не запрограммирован жестко. Может есть способ прописать в конце слушателя OnClickListener метод который будет снова прописывать текст каждый раз после расчёта? Или может вовсе заменить слушателя на метод onClick?
Помогите пожалуйста! Проблема незначительная, но очень досадная. Сам не могу справиться.
Вот код разметки:
| HTML5 |
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
| <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context="irokezer58.kvadurforandroid_40.MainActivity">
<TextView
android:id="@+id/textZagl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/zagl"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@color/Lime"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/aEdit"
android:layout_width="54dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberSigned"
android:shadowColor="@color/White"
android:text="@string/a"
android:textAlignment="center"
android:textColor="@color/Lime"
android:textColorHighlight="@android:color/holo_blue_bright"
android:textColorHint="?attr/colorPrimaryDark"
android:textColorLink="@color/White"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/textXq"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/bEdit"
android:layout_width="55dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberSigned"
android:text="@string/b"
android:textAlignment="center"
android:textColor="@color/Lime"
android:textColorLink="@color/White"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/textX"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/cEdit"
android:layout_width="55dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberSigned"
android:text="@string/c"
android:textAlignment="center"
android:textColor="@color/Lime"
android:textColorLink="@color/White"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/textZero"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textXq"
android:layout_width="55dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/xQ"
android:textAlignment="center"
android:textColor="@color/Lime"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/bEdit"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textX"
android:layout_width="54dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/x"
android:textAlignment="center"
android:textColor="@color/Lime"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/cEdit"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.501" />
<TextView
android:id="@+id/textZero"
android:layout_width="55dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/zero"
android:textAlignment="center"
android:textColor="@color/Lime"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonRashc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@color/Lime"
android:text="@string/ButtonRaschot"
android:textColor="@color/Dark"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bEdit" />
<TextView
android:id="@+id/textVasheUr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/Lime"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textZagl" />
<TextView
android:id="@+id/textmUr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/Lime"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textVasheUr" />
<TextView
android:id="@+id/textDiskrim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/Lime"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textmUr" />
<TextView
android:id="@+id/textmDiskrim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/Lime"
app:layout_constraintLeft_toRightOf="@+id/textDiskrim"
app:layout_constraintTop_toBottomOf="@+id/textmUr" />
<TextView
android:id="@+id/textmOtvet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/Lime"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textDiskrim" />
<TextView
android:id="@+id/textmXX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/Lime"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/bEdit"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textmOtvet" />
</android.support.constraint.ConstraintLayout> |
|
Вот код программы:
| 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| package irokezer58.kvadurforandroid_40;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Button mRashcot;
private EditText mCoefa;
private EditText mCoefb;
private EditText mCoefc;
private TextView mFirsStrin;
private TextView mTwoString;
private TextView mTreeString;
private TextView mFourString;
private TextView mFiveString;
private TextView mXX;
double tmp02a;
String tmp01a;
double tmp02b;
String tmp01b;
double tmp02c;
String tmp01c;
double mDs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRashcot = (Button)findViewById(R.id.buttonRashc);
mFirsStrin = (TextView)findViewById(R.id.textVasheUr);
mTwoString = (TextView)findViewById(R.id.textmUr);
mTreeString = (TextView)findViewById(R.id.textDiskrim);
mFourString = (TextView)findViewById(R.id.textmDiskrim);
mFiveString = (TextView)findViewById(R.id.textmOtvet);
mXX = (TextView)findViewById(R.id.textmXX);
mRashcot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRashcot.setText("");
mFirsStrin.setText("");
mTwoString.setText("");
mTreeString.setText("");
mFourString.setText("");
mFiveString.setText("");
mXX.setText("");
mCoefa = (EditText)findViewById(R.id.aEdit);
mCoefb = (EditText)findViewById(R.id.bEdit);
mCoefc = (EditText)findViewById(R.id.cEdit);
tmp01a = mCoefa.getText().toString();
if (tmp01a==null) tmp02a = 0;
else{
tmp02a = new Double(tmp01a);}
tmp01b = mCoefb.getText().toString();
if (tmp01b==null) tmp02b = 0;
else{
tmp02b = new Double(tmp01b);}
tmp01c = mCoefc.getText().toString();
if (tmp01c==null) tmp02c = 0;
else{
tmp02c = new Double(tmp01c);}
QadUr Urav = new QadUr (tmp02a, tmp02b, tmp02c);
mFirsStrin.setText("Ваше уравнение:");
Urav.Diskrim();
Urav.createUravneniye();
mDs = Urav.getD();
mTwoString.setText(Urav.getmUravneniye());
mTreeString.setText("Дискриминант уравнения = ");
mFourString.setText(Urav.getmDString());
// КОГДА КОРНЕЙ НЕТ
if (mDs<0) {
mFiveString.setText("Дискриминант - отрицательное число. Уравнение не имеет корней.");
}
if (mDs==0){
mFiveString.setText("Дискриминант равен нулю. Уравнение имеет один корень.");
Urav.X_1();
mXX.setText("x = "+Urav.getX1());
}
if (mDs>0){
mFiveString.setText("Дискриминант - положительное число. Уравнение имеет два корня.");
Urav.X_1();
Urav.X_2();
mXX.setText("x1 = "+Urav.getX1()+"\n"+"x2 = "+Urav.getX2());
}
}
});
}
} |
|
Вот код ресурсов (на всякий случай):
| HTML5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <resources>
<string name="app_name">Квадратные уравнения</string>
<string name="a">а</string>
<string name="b">b</string>
<string name="c">c</string>
<string name="x">x+</string>
<string name="xQ">x^2+</string>
<string name="zero">=0</string>
<string name="plus">+</string>
<string name="ravno">=</string>
<string name="zagl">Решение квадратного уравнения</string>
<string name="ButtonRaschot">Расчёт</string>
<string name="Diskrim">Дискриминант уравнения = </string>
<string name="KorneyNet">Дискриминант - отрицательное число. Корней нет.</string>
<string name="OdinKoren">Дискриминант равен нулю. Уравнение имеет один корень.</string>
<string name="DvaKornya">Дискриминант - положительное число. Уравнение имеет два корня.</string>
<string name="Vashe">Ваше уравнение:</string>
<string name="about_title">Неизвестная надпись</string>
<string name="tmp">0</string>
</resources> |
|
Надеюсь я правильно разместил код в посте.
Пожалуй приложу скриншоты пропавшей надписи в эмуляторе: