新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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(); } } }