Thursday, April 25, 2013

[android help] My Runner using a Handler is not working on android


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

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...