new AlertDialog.Builder(DataMeasureActivity1.this) .setTitle("舒適提示") .setMessage("開始接收數據 ?") .setPositiveButton("開始", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { timer = new Timer(); //計時任務開始 timer.schedule(new MyTimeTask(), 100, 10000); recvFlagImg.setImageDrawable(DataMeasureActivity1.this.getResources().getDrawable(R.drawable.an_button_off)); } }) .setNeutralButton("中止", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { recvFlagImg.setImageDrawable(DataMeasureActivity1.this.getResources().getDrawable(R.drawable.an_button_on)); timer.cancel(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show();