This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
He's giving us the slip! Quick! Grab this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic