Android实现简单的倒计时功能
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(); } } }
新闻名称:Android实现简单的倒计时功能
当前网址:http://azwzsj.com/article/iisesd.html