Java 如何在倒计时中使用我的另一门课中的按钮|初学者

Java 如何在倒计时中使用我的另一门课中的按钮|初学者,java,class,button,Java,Class,Button,我正在创建一个反应时测试应用程序,只有一个按钮。我在第一个类中创建了这个按钮:ReactionTestActivity。现在我想在我的倒计时中使用它,但是我该怎么做呢 public class CDT extends CountDownTimer { public CDT (long millisInFuture, long countDownInterval, ReactionTestActivity RAT){ super(millisInFuture, count

我正在创建一个反应时测试应用程序,只有一个按钮。我在第一个类中创建了这个按钮:ReactionTestActivity。现在我想在我的倒计时中使用它,但是我该怎么做呢

public class CDT extends CountDownTimer {

    public CDT (long millisInFuture, long countDownInterval, ReactionTestActivity RAT){
        super(millisInFuture, countDownInterval);

    }


    public void onFinish(){
        button.setText("press");
    }



    @Override
    public void onTick(long millisUntilFinished) {
    }

}

您刚刚创建了这个类。假设你在做安卓,你需要做安卓的其他工作:

public class TimerActivity extends Activity implements OnClickListener {

    private CountDownTimer countDownTimer;
    private boolean timerHasStarted = false;
    private Button startB;
    public TextView text;
    private final long startTime = 30 * 1000;
    private final long interval = 1 * 1000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timer);
        startB = (Button) this.findViewById(R.id.button);
        startB.setOnClickListener(this);
        text = (TextView) this.findViewById(R.id.timer);

        //NOTE:  I don't know what you expect as the third parameter
        countDownTimer = new CDT(startTime, interval, null);

        text.setText(text.getText() + String.valueOf(startTime/1000));
    }

    @Override
    public void onClick(View v) {
        if (!timerHasStarted) {
             countDownTimer.start();
             timerHasStarted = true;
             startB.setText("STOP");
         } else {
             countDownTimer.cancel();
             timerHasStarted = false;
             startB.setText("RESTART");
         }
    }


    public class CDT extends CountDownTimer {
        //your class definition that you wrote above.
    }

}
现在您需要XML:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/bgi" >

<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:paddingRight="10dip"
android:textSize="50dp" />

<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Start" />

</RelativeLayout>

资料来源:


什么样的运行时环境?摆动安卓?我想倒数计时器只是安卓而已。