Pb Changement de vue avec Animation + thread
Bonjour à tous,
Voila ce que je veux faire:
Je souhaite avoir une première vue (index.xml) composé d'une simple image avec animation. Dans l'exemple ci-dessous, j'ai changé la vue par une image car je ne comprends pas d'où viens mon pb.
Je souhaite qu'au bout de 10s, une autre vue (main.xml) soit affichée automatiquement.
J'ai tout basiquement fais quelque chose comme ça:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.animation);
final ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.google);
setContentView(iv);
iv.startAnimation(animation1);
try{
/* attends 10 s*/
Thread.sleep(10000) ;
setContentView(R.layout.main);
}
catch(Exception e){ }
} |
Mon problème: soit j'ai l'animation mais pas le thread. et si j'enlève l'animation, j'ai le changement de vue avec le thread.
Donc, comme ça marchait pas bien, j'ai changé par quelque chose d'un peu plus costaud:
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
| protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.animation);
final Toast toast = Toast.makeText(this, "hello", Toast.LENGTH_SHORT);
final ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.google);
setContentView(iv);
Thread threadArrierePlan = new Thread(new Runnable(){
public void run(){
try{
Thread.sleep(10000) ;
setContentView(R.layout.main);
toast.setGravity(Gravity.TOP, 0, 40);
toast.show();
}
catch(Throwable t){}
}
});
threadArrierePlan.start(); |
J'affiche bien le toast mais même sanction. Donc je ne sais plus trop ou cherché là
Merci pour vos aides et commentaire.