Фриз кнопки android studio
я новичок в программировании. Изучаю Java, android разработку. Недавно я начал писать простое приложение-викторину. Я столкнулся с проблемой которую никак не могу решить. Суть заключается в фризе, из которого нельзя выйти. Это происходит при нажатии на кнопку. Прикрепляю архив с проектом и видео фриза. Так-же этот фриз происходит только при умножении или делении и тд(6-16 лвла). https://drive.google.com/open?id=1ZJOlEmmpCHBzsil2bA55-U1O_9Oq-DPK https://drive.google.com/open?id=1ot_bdciwOnKeC4REXDC_jW7uvztJgAkC
Вот код 16 уровня
public class Level16 extends AppCompatActivity {
public int count = 0;
Dialog dialog, dialogEnd, dialogLose;
private long backPressedTime;
private Toast backToast;
public int numLeft, numRight, numLeft1, numRight1, numLeft2, numRight2, numLeftS, numLeft1n, numRightS, numRight1n; //переменные для кнопок
Random random = new Random();
Button btr, btl;
public ProgressBar pb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.universal);
pb = findViewById(R.id.pBar);
final CountDownTimer tillTheEnd = new CountDownTimer(35000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
pb.setMax(35);
pb.setProgress((int)(millisUntilFinished/1000));
}
@Override
public void onFinish() {
dialogLose.show();
}
}.start();
final int[] progress = {
R.id.p1, R.id.p2, R.id.p3, R.id.p4, R.id.p5,
R.id.p6, R.id.p7, R.id.p8, R.id.p9, R.id.p10,
R.id.p11, R.id.p12, R.id.p13, R.id.p14, R.id.p15
};
final Animation a = AnimationUtils.loadAnimation(Level16.this, R.anim.alpha);
btl = findViewById(R.id.answ1);
btr = findViewById(R.id.answ2);
//начало
int promL,promR,promM,promB;
promL = random.nextInt(2);
if(promL==1){
numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1 + "²" + " + " + numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1 + "²" + " - " + numLeft2);
}
}else{
numLeft1=random.nextInt(3);
numLeft1n=random.nextInt(3);
while(numLeft1n==0) numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1n;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" + "+numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" - "+numLeft2);
}
}
promR = random.nextInt(2);
if(promR==1){
numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1 + "²" + " + " + numLeft2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1 + "²" + " - " + numLeft2);
}
}else{
numRight1=random.nextInt(3);
numRight1n=random.nextInt(3);
while(numRight1n==0) numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1n;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1+"×"+numRight1n+" + "+numRight2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1+"×"+numRight1n+" - "+numRight2);
}
}
while(numLeft==numRight){
promL = random.nextInt(2);
if(promL==1){
numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1 + "²" + " + " + numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1 + "²" + " - " + numLeft2);
}
}else{
numLeft1=random.nextInt(3);
numLeft1n=random.nextInt(3);
while(numLeft1n==0) numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1n;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" + "+numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" - "+numLeft2);
}
}
promR = random.nextInt(2);
if(promR==1){
numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1 + "²" + " + " + numLeft2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1 + "²" + " - " + numLeft2);
}
}else{
numRight1=random.nextInt(3);
numRight1n=random.nextInt(3);
while(numRight1n==0) numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1n;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1+"×"+numRight1n+" + "+numRight2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1+"×"+numRight1n+" - "+numRight2);
}
}
}
//конец
btl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
btr.setEnabled(false);
if(numLeft>numRight){
btl.setBackgroundResource(R.drawable.correct_answ);
btr.setBackgroundResource(R.drawable.wrong_answer);
if(count<15) count++;
try{
for (int i=0; i<15; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.progress_point);
} }catch (Exception e){
Log.d("Error is in grey points", "LeftGreyPoints");
}
for(int i=0; i<count; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.green_progress_point);
}
}else{
btr.setBackgroundResource(R.drawable.correct_answ);
btl.setBackgroundResource(R.drawable.wrong_answer);
if(count>0) if (count==1) count=0; else count=count-2;
try{
for (int i=0; i<14; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.progress_point);
} }catch (Exception e){
Log.d("Error is in left grey points 2", "LeftGreyPoints2");
}
for(int i=0; i<count; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.green_progress_point);
}
}
if (count == 15){
tillTheEnd.cancel();
dialogEnd.show();
//выход из уровня
}else{
//начало
int promL,promR,promM,promB;
promL = random.nextInt(2);
if(promL==1){
numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1 + "²" + " + " + numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1 + "²" + " - " + numLeft2);
}
}else{
numLeft1=random.nextInt(3);
numLeft1n=random.nextInt(3);
while(numLeft1n==0) numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1n;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" + "+numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" - "+numLeft2);
}
}
promR = random.nextInt(2);
if(promR==1){
numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1 + "²" + " + " + numLeft2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1 + "²" + " - " + numLeft2);
}
}else{
numRight1=random.nextInt(3);
numRight1n=random.nextInt(3);
while(numRight1n==0) numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1n;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1+"×"+numRight1n+" + "+numRight2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1+"×"+numRight1n+" - "+numRight2);
}
}
while(numLeft==numRight){
promL = random.nextInt(2);
if(promL==1){
numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1 + "²" + " + " + numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1 + "²" + " - " + numLeft2);
}
}else{
numLeft1=random.nextInt(3);
numLeft1n=random.nextInt(3);
while(numLeft1n==0) numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1n;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" + "+numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" - "+numLeft2);
}
}
promR = random.nextInt(2);
if(promR==1){
numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1 + "²" + " + " + numLeft2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1 + "²" + " - " + numLeft2);
}
}else{
numRight1=random.nextInt(3);
numRight1n=random.nextInt(3);
while(numRight1n==0) numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1n;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1+"×"+numRight1n+" + "+numRight2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1+"×"+numRight1n+" - "+numRight2);
}
}
}
//конец
btl.startAnimation(a);
btr.startAnimation(a);
btr.setEnabled(true);
}
btl.setBackgroundResource(R.drawable.start_btn_stroke);
btr.setBackgroundResource(R.drawable.start_btn_stroke);
}catch (Exception e){}
}
});
btr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
btl.setEnabled(false);
if(numRight>numLeft){
btr.setBackgroundResource(R.drawable.correct_answ);
btl.setBackgroundResource(R.drawable.wrong_answer);
if(count<15) count++;
try{
for (int i=0; i<15; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.progress_point);
} }catch (Exception e){
Log.d("Error is in right grey points", "RightGreyPoints");
}
for(int i=0; i<count; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.green_progress_point);
}
}else {
btl.setBackgroundResource(R.drawable.correct_answ);
btr.setBackgroundResource(R.drawable.wrong_answer);
if(count>0) if (count==1) count=0; else count=count-2;
try{
for (int i=0; i<14; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.progress_point);
} }catch (Exception e){
Log.d("Error is in right grey points 2", "RightGreyPoints2");
}
for(int i=0; i<count; i++){
TextView tv = findViewById(progress[i]);
tv.setBackgroundResource(R.drawable.green_progress_point);
}
}
if (count == 15){
tillTheEnd.cancel();
dialogEnd.show();
//выход из уровня
}else{
//начало
int promL,promR,promM,promB;
promL = random.nextInt(2);
if(promL==1){
numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1 + "²" + " + " + numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1 + "²" + " - " + numLeft2);
}
}else{
numLeft1=random.nextInt(3);
numLeft1n=random.nextInt(3);
while(numLeft1n==0) numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1n;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" + "+numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" - "+numLeft2);
}
}
promR = random.nextInt(2);
if(promR==1){
numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1 + "²" + " + " + numLeft2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1 + "²" + " - " + numLeft2);
}
}else{
numRight1=random.nextInt(3);
numRight1n=random.nextInt(3);
while(numRight1n==0) numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1n;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1+"×"+numRight1n+" + "+numRight2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1+"×"+numRight1n+" - "+numRight2);
}
}
while(numLeft==numRight){
promL = random.nextInt(2);
if(promL==1){
numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1 + "²" + " + " + numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1 + "²" + " - " + numLeft2);
}
}else{
numLeft1=random.nextInt(3);
numLeft1n=random.nextInt(3);
while(numLeft1n==0) numLeft1=random.nextInt(3);
while(numLeft1==0) numLeft1=random.nextInt(3);
numLeftS=numLeft1*numLeft1n;
numLeft2=random.nextInt(3);
while(numLeft2==0) numLeft2=random.nextInt(3);
promM=random.nextInt(1);
if (promM==1){
numLeft=numLeftS+numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" + "+numLeft2);
}else{
numLeft=numLeftS-numLeft2;
btl.setText(numLeft1+"×"+numLeft1n+" - "+numLeft2);
}
}
promR = random.nextInt(2);
if(promR==1){
numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1 + "²" + " + " + numLeft2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1 + "²" + " - " + numLeft2);
}
}else{
numRight1=random.nextInt(3);
numRight1n=random.nextInt(3);
while(numRight1n==0) numRight1=random.nextInt(3);
while(numRight1==0) numRight1=random.nextInt(3);
numRightS=numRight1*numRight1n;
numRight2=random.nextInt(3);
while(numRight2==0) numRight2=random.nextInt(3);
promB=random.nextInt(1);
if (promB==1){
numRight=numRightS+numRight2;
btr.setText(numRight1+"×"+numRight1n+" + "+numRight2);
}else{
numRight=numRightS-numRight2;
btr.setText(numRight1+"×"+numRight1n+" - "+numRight2);
}
}
}
//конец
btl.startAnimation(a);
btr.startAnimation(a);
btl.setEnabled(true);
}
btl.setBackgroundResource(R.drawable.start_btn_stroke);
btr.setBackgroundResource(R.drawable.start_btn_stroke);
}catch (Exception e){}}
});
}