• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to change the ImageView's picture at runtime, after 2 sec, 5 sec and 7 sec.  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to make it with thread, but with the thread I can't change it. Now I tried to make a handler but it's not good either.

Here is the original thread code:



I hope you can understand what I want to do, sorry I'm not perfect english If you can, please give me an alternative code for this. It's very annoying, that only this is what I need for my program, but I can't do this. Sorry if this question, is so easy or something but I'm a beginner programmer.
 
Ranch Hand
Posts: 252
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this.
Thread t=new Thread(new Runnable() {

public void run()
{
try
{
Thread.sleep(2000);// After 2 seconds
//Change Image
Thread.sleep(5000);// After 5 seconds
//Change Image
Thread.sleep(7000);// After 7 seconds
//Change Image
}
catch(Exception e)
{

}
}
});
t.start();
 
D Hagy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hardik Trivedi wrote:You can try this.
Thread t=new Thread(new Runnable() {

public void run()
{
try
{
Thread.sleep(2000);// After 2 seconds
//Change Image
Thread.sleep(5000);// After 5 seconds
//Change Image
Thread.sleep(7000);// After 7 seconds
//Change Image
}
catch(Exception e)
{

}
}
});
t.start();



Thanks! I will try it tomorrow (ehhmm... today )
 
D Hagy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hardik Trivedi wrote:You can try this.
Thread t=new Thread(new Runnable() {

public void run()
{
try
{
Thread.sleep(2000);// After 2 seconds
//Change Image
Thread.sleep(5000);// After 5 seconds
//Change Image
Thread.sleep(7000);// After 7 seconds
//Change Image
}
catch(Exception e)
{

}
}
});
t.start();



Thanks, I tried it. My application doesn't show any error, or warning, but it's produce the "stopped unexpectedly" error. Can this produce it, or there is an another problem?
 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

D Hagy wrote:I tried to make it with thread, but with the thread I can't change it. Now I tried to make a handler but it's not good either.

Here is the original thread code:



I hope you can understand what I want to do, sorry I'm not perfect english If you can, please give me an alternative code for this. It's very annoying, that only this is what I need for my program, but I can't do this. Sorry if this question, is so easy or something but I'm a beginner programmer.



I didn't actually try it, but when you say " but with the thread I can't change it", I'm assuming that you are getting a CalledFromWrongTreadException (you can see the exception in the LogCat).
The line radar.setImageResource(R.drawable.radar_full); and other two need to run on the UI thread, so replace this single line with the following block - the other two would need to be changed too :

 
D Hagy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nidhi Sar wrote:

D Hagy wrote:I tried to make it with thread, but with the thread I can't change it. Now I tried to make a handler but it's not good either.

Here is the original thread code:



I hope you can understand what I want to do, sorry I'm not perfect english If you can, please give me an alternative code for this. It's very annoying, that only this is what I need for my program, but I can't do this. Sorry if this question, is so easy or something but I'm a beginner programmer.



I didn't actually try it, but when you say " but with the thread I can't change it", I'm assuming that you are getting a CalledFromWrongTreadException (you can see the exception in the LogCat).
The line radar.setImageResource(R.drawable.radar_full); and other two need to run on the UI thread, so replace this single line with the following block - the other two would need to be changed too :



Thanks I could make it!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!