我正在构建一个篮球比分时钟应用程序。我让主计时器运行良好。当我点击它时,它会启动时钟,当我再次点击它时,它会停止时钟。这很完美。
我已经实例化了第二个对象,它是用于拍摄时钟的。但是,onClick
对于第二个文本视图,该事件根本没有触发。
这两个onClick
事件都设置在 TextView 元素上。我不知道为什么onClickShotClock(View view)
当我单击第二个文本视图时该方法没有触发。
我知道该对象已正确实例化,因为它正确设置了值,并且该值是通过代码设置来实例化它的。
谁能看到这不起作用?
package com.example.ultimatescoreclock;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.os.CountDownTimer;
import com.example.ultimatescoreclock.ScoreClock;
public class MainActivity extends Activity {
TextView strMainClock, strShotClock;
ScoreClock timerMainClock, timerShotClock;
long msSavedMainClock = 0;
long msSavedShotClock = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
strMainClock = (TextView) findViewById(R.id.clockMain);
strShotClock = (TextView) findViewById(R.id.clockShot);
timerMainClock = new ScoreClock( 13000, 100, strMainClock );
timerShotClock = new ScoreClock( 8000, 100, strShotClock );
strMainClock.setText( timerMainClock.getTimeLeft() );
strShotClock.setText( timerShotClock.getTimeLeft() );
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onMainClockClick(View view) {
if ( !timerMainClock.isRunning ) {
if ( msSavedMainClock != 0 )
timerMainClock = new ScoreClock( msSavedMainClock, 100, strMainClock );
timerMainClock.start();
timerMainClock.isRunning = !timerMainClock.isRunning;
} else {
timerMainClock.cancel();
msSavedMainClock = timerMainClock.msRemaining;
timerMainClock.isRunning = !timerMainClock.isRunning;
}
}
public void onShotClockClick(View view) {
strShotClock.setText("go!");
/*
if ( !timerShotClock.isRunning ) {
if ( msSavedShotClock != 0 )
timerShotClock = new ScoreClock( msSavedShotClock, 100, strShotClock );
timerShotClock.start();
timerShotClock.isRunning = !timerShotClock.isRunning;
} else {
timerShotClock.cancel();
msSavedShotClock = timerShotClock.msRemaining;
timerShotClock.isRunning = !timerShotClock.isRunning;
}
*/
}
}