IntelliJ Java IDE
The moose likes Android and the fly likes Want to change the ImageView's picture at runtime, after 2 sec, 5 sec and 7 sec. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "Want to change the ImageView Watch "Want to change the ImageView New topic
Author

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

D Hagy
Greenhorn

Joined: Jul 05, 2011
Posts: 12
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.
Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
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

Joined: Jul 05, 2011
Posts: 12
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

Joined: Jul 05, 2011
Posts: 12
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?
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

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 :



"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
D Hagy
Greenhorn

Joined: Jul 05, 2011
Posts: 12
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!
 
 
subject: Want to change the ImageView's picture at runtime, after 2 sec, 5 sec and 7 sec.
 
Threads others viewed
readObject() eat memory !!!
Mms and sms at the same midlet
is it possible to create a singleton thread class?
Printing from threads in a particular sequence
Waiting for input from PipedInputStream....thread yield?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture