Erreur KeyDispatchingTimedOut ANR
Bonjour,
je développe une application Android dans laquelle j'aimerais implémenter un compte à rebours.
Pour ce faire, j'utilise la classe CountDownTimer que j'essaie de customizer en mettant en pause par exemple le compteur via un bouton.
Voici le code qui pourra peut être vous éclairer d'avantage sur cette erreur qui se produit entre laligne 68 et 82
Code:
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
|
package com.poker;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class CountDown extends Activity implements OnClickListener {
private TextView tv;
private MyCount counter;
private Button pause;
private Button play;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this);
pause = new Button(this);
pause.setText("pause");
pause.setOnClickListener(this);
play = new Button(this);
play.setText("play");
play.setOnClickListener(this);
layout.addView(tv);
layout.addView(pause);
layout.addView(play);
this.setContentView(layout);
counter = new MyCount(5000, 1000);
counter.start();
}
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
tv.setText("done!");
}
@Override
public void onTick(long millisUntilFinished) {
tv.setText("Left: " + millisUntilFinished / 1000);
}
}
@Override
public void onClick(View v) {
if (v==pause) {
try {
synchronized (counter) {
changeButtons();
counter.wait();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
notifyAll();
}
}
private void changeButtons(){
pause.setClickable(false);
play.setClickable(true);
}
} |
Merci pour votre aide