Hello!
I am new to android development, also new to java. I have many years
of experience with OO PHP, so it's not hard for me to quickly learn
Java and Android, but I still don't know many things like Thread
class.
I just started developing a simple app.
What I want to do is that when a button is clicked, then the TextView
is update in this way:
the background is changed to black (by default it's set to white)
Then it should wait a half a second and then set the background back
to white and update the text inside the TextView
Here is my code, it's inside my Activity class:
public synchronized void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnPlay:
showNewDraw();
break;
}
}
protected void showNewDraw() {
textResult.setBackgroundColor(Color.BLACK);
textResult.setText("Before sleep");
try {
Thread.sleep(500);
} catch (Exception e) {
textResult.setText("Something wrong");
}
textResult.setBackgroundColor(Color.WHITE);
textResult.setText("After sleep");
}
The way it works now is that it seems to actually take 1/2 second from
the time the button is pressed and text is updated, but the background
is not reset to black and back to white - it always stays white.
Either it is being set to black and instantly reset to white or it's
just never set to black.
What should I do in order for the "delay" effect to work?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en