Skip to content

Instantly share code, notes, and snippets.

@icarofreire
Created October 18, 2014 02:56
Show Gist options
  • Save icarofreire/991652ccfbade9b72fc8 to your computer and use it in GitHub Desktop.
Save icarofreire/991652ccfbade9b72fc8 to your computer and use it in GitHub Desktop.
Trocar por meio de Thread, o background de uma imagem durante um evento de uma aplicação Android.
public void swap(final Activity atividade, final View v, final int R_drawable_imagem_widget_1, final int R_drawable_imagem_widget_2)
{
v.setBackgroundResource(R_drawable_imagem_widget_1);
new Thread(new Runnable()
{
public void run()
{
try{/* \/ Para a execução por N milissegundos. */
Thread.sleep(200);/* <- 200 milissegundos.*/
} catch (InterruptedException e)
{ e.printStackTrace(); }
atividade.runOnUiThread(new Runnable()
{
public void run(){
v.setBackgroundResource(R_drawable_imagem_widget_2);
}
});
}
}).start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment