public class MainActivity extends Activity { private TextView textview; private Button but1; private int count=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textview=(TextView)findViewById(R.id.mytextview); but1=(Button)findViewById(R.id.but1); But1 b=new But1(); but1.setOnClickListener(b); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } class But1 implements OnClickListener{ @Override public void onClick(View v) { new CountDownTimer(30000,1000) { @Override public void onTick(long millisUntilFinished) { textview.setText("请等待30秒(" + millisUntilFinished / 1000 + ")..."); } @Override public void onFinish() { Toast.makeText(getApplicationContext(), "倒计时结束", Toast.LENGTH_SHORT).show(); } }.start(); } } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。