Here's what I got so far guys, this is my app, all it does is display a digital clock and move the clock to a new part of the screen every 30 seconds, but it doesn't actually do that last part, here's the code:
public class MainActivity extends Activity {
private Runnable runnable = new Runnable(){
@Override
public void run() {
handler.sendEmptyMessage(0);
}
};
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
//change the text position here
this.postDelayed(runnable , 30000);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.digitalClock);
Random r = new Random();
Thread thread =new Thread(runnable );
thread.start();
int x = r.nextInt(350 - 100);
int y = r.nextInt(800 - 100);
textView.setX(x);
textView.setY(y);
}
I just cant seem to get this to work, been scanning the internet for about a week now. I think it's got something to do with the "New Thread" but not too sure what.
.
stackoverflow.comm
No comments:
Post a Comment