标签:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txt=(TextView)findViewById(R.id.showTime); final Handler myHandler=new Handler() { @Override public void handleMessage(Message msg) { if(msg.what==0x12) { txt.setText("当前时间:"+new java.util.Date()); } } }; Button btn=(Button)findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub new Timer().schedule(new TimerTask() { @Override public void run() { // TODO Auto-generated method stub myHandler.sendEmptyMessage(0x12); } }, 0,1000); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
标签:
原文地址:http://www.cnblogs.com/zhouhb/p/5812447.html