i am developing a game.i want to display score on button click.but it should be displayed only for few seconds.i want to implement timer in my app.but i dnt knw how to implement that.i searched in the google.but results were confusing me…given below is my code snippet.plz anybody help me…
OnClickListener clickball=new OnClickListener() {
@Override
public void onClick(View v) {
score=scorenumber.nextInt(9);
id=v.getId();
Log.v("", "u clicked me");
if(id==R.id.ball2)
{
ball2.setText(Integer.toString(score));
}
else if(id==R.id.ball3)
{
ball3.setText(Integer.toString(score));
}
else if(id==R.id.ball5)
{
ball5.setText(Integer.toString(score));
}
}
}
No need to go so deep in your case. Every view has postDelayed() method, that will run a custom code in UI thread after a set amount of time (in milliseconds). For example:
will clear “ball5” text after 3 seconds has passed
Another example
…
…