这个需要在输出,点击start后会隔一会输出一行字,点end会结束输出。
Code package tk.handleractivity;import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;public class MyHangler extends Activity {private Button startButton=null;private Button endButton=null;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.myhangler);startButton=(Button)findViewById(R.id.startButton);startButton.setOnClickListener(new StartbuttonListener());endButton=(Button)findViewById(R.id.endButton);endButton.setOnClickListener(new EndbuttonListener());}class StartbuttonListener implements OnClickListener{@Overridepublic void onClick(View v) {handler.post(updateThead);} }class EndbuttonListener implements OnClickListener{@Overridepublic void onClick(View v) {handler.removeCallbacks(updateThead);} }@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.myhangler, menu);return true;}Handler handler=new Handler();Runnable updateThead=new Runnable() {@Overridepublic void run() {System.out.println("UpdateThead");handler.postDelayed(updateThead, 3000);}}; }