2017-12-15 12 views
1

私はボタンが行くと、他の 文字で戻ってきて、初めてを押して、私は再び押すと、何も起こりません:
int d = -1;String btnanim = "0";
を私はもう一度ボタンを押したときに、それがアニメーションにする方法は?アニメーションなしアニメーションでボタンのテキストが次のクリックに変更されないのはなぜですか?

public void b_b1(View v) { 
    if (this.btnanim == "AB") { 
     btn("CD"); 
     return; 
    } 
    do { 
     if (this.btnanim == "CD") { 
      btn("EF"); 
      return; 
     } 
     if (this.btnanim == "EF") { 
      btn("GH"); 
      return; 
     } 
    } while (this.btnanim != "1"); 
    btn("AB"); 
} 

、テキストは

void btn(String str) { 
    this.btnanim = str; 
    this.timer.schedule(new TimerTask() { 
     ObjectAnimator anim; 
     LinearLayout bgroup = (LinearLayout) MainActivity.this.findViewById(R.id.bg); 
     Button b1 = (Button) MainActivity.this.findViewById(R.id.b1); 
     Button b2 = (Button) MainActivity.this.findViewById(R.id.b2); 

     public void run() { 
      MainActivity.this.runOnUiThread(new Runnable() { 
       public void run() { 
        MainActivity.this.d += 1; 
         switch (MainActivity.this.d) { 
          case 0: 
           anim = ObjectAnimator.ofFloat(bgroup, "translationX", bgroup.getWidth() * 2); 
           anim.setDuration(500L).start(); 
           break; 
          case 5: 
           anim = ObjectAnimator.ofFloat(bgroup, "translationX", -bgroup.getWidth() * 2); 
           anim.setDuration(0L).start(); 
           anim = ObjectAnimator.ofFloat(bgroup, "translationX", 0); 
           anim.setDuration(500L).start(); 
           switch (MainActivity.this.btnanim) { 
            case "AB": 
             b1.setText("A"); 
             b2.setText("B"); 
             break; 
            case "CD": 
             b1.setText("C"); 
             b2.setText("D"); 
             break; 
            case "EF": 
//Do not repeat the animation this: Changes A and B to C and D then nothing 

             b1.setText("E"); 
             b2.setText("F"); 
             break; 
           } 
         } 
        } 
       }); 
      } 
     }, 0L, 100L); 
    } 


    protected void onResume() { 
     super.onResume(); 
     MainActivity.this.btnanim = "AB"; 
    } 
} 
+0

'this.btnanim =" 1 "'を設定したことはありません。だから 'this.btnanim!=" 1 "'は常に真です。そこに無限ループがあるように見えます。 – 0X0nosugar

+0

私はしばらく清掃しまし​​た。初めてアニメーションが実行されます。ボタンの文字が変わります。 b1 = A-> Cb2 = B-> Dです。b1 = C-> E、b2 = D-> Fをもう一度押すと、アニメーションは移動しません。私は、コードにサイクルを入れる必要があることを理解していますが、どのように、どこで、どこに置いてください。 – User9113

答えて

0

を変更し、私は今、それが正しく動作void btn(String str) {}

this.d = -1;を追加しました!

関連する問題