publicclassMainActivityextendsActivity{privateTextViewtextview;privateButtonbut1;privateintcount=0;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);textview=(TextView)findViewById(R.id.mytextview);but1=(Button)findViewById(R.id.but1);But1b=newBut1();but1.setOnClickListener(b);}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){getMenuInflater().inflate(R.menu.main,menu);returntrue;}@OverridepublicbooleanonOptionsItemSelected(MenuItemitem){intid=item.getItemId();if(id==R.id.action_settings){returntrue;}returnsuper.onOptionsItemSelected(item);}classBut1implementsOnClickListener{@OverridepublicvoidonClick(Viewv){newCountDownTimer(30000,1000){@OverridepublicvoidonTick(longmillisUntilFinished){textview.setText("请等待30秒("+millisUntilFinished/1000+")...");}@OverridepublicvoidonFinish(){Toast.makeText(getApplicationContext(),"倒计时结束",Toast.LENGTH_SHORT).show();}}.start();}}}