I want to refresh a TextView's text per minute when Digital Clock refresh the time with the format hh/mm
every minute. I put a TextView named txtView1 in the Activity and create a class Digital Clock.When I run the app,However,the app exits with error.I really don't konw why
here is the important function onAttachedToWindow()
about the Digital Clock:
protected void onAttachedToWindow() {
mTickerStopped = false;
super.onAttachedToWindow();
mHandler = new Handler();
/**
* requests a tick on the next hard-second boundary
*/
mTicker = new Runnable() {
public void run() {
if (mTickerStopped) return;
mCalendar.setTimeInMillis(System.currentTimeMillis());
String content = (String) DateFormat.format(mFormat, mCalendar);
if(content.split(" ").length > 1){
content = content.split(" ")[0] + content.split(" ")[1];
}
setText(android.text.Html.fromHtml(content));
//-----Here is the TextView I want to refresh
TextView txtV1 = (TextView)findViewById(R.id.txtView1);
txtV1.setText("Now Fresh");//Just for try,so set a constant string
invalidate();
long now = SystemClock.uptimeMillis();
//refresh each minute
long next = now + (60*1000 - now % 1000);
mHandler.postAtTime(mTicker, next);
}
};
mTicker.run();
}