当我点击按钮时,我的应用程序崩溃,我不明白为什么。我已多次查找我的代码,但似乎无法找到任何"主要缺陷"。该应用程序的目的是尽可能快地单击按钮两次,它显示从第一次点击到第二次点击所需的时间。某种反应的事情。我用了一个计时器因为我不知道还能用什么。 (开始时间的值) - (当前计时器的值)=(第一次和第二次点击之间的时间)。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context="com.keklabs.reactiontimer.MainActivity">
<TextView
android:id="@+id/scoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="78dp"
android:text="Click below to start!"
android:textColor="#39FF14"
android:textSize="30dp" />
<Button
android:id="@+id/startStopButton"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#000000"
android:text="Start / Stop"
android:textSize="25dp"
android:textColor="#39FF14" />
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
private final long startTime = 0;
private final long interval = 100;
private boolean buttonClicked;
private Button startStopButton;
private TextView scoreText;
CountDownTimer timer = new CountDownTimer(30000, 100) {
@Override
public void onTick(long millisUntilFinished) {
scoreText.setText("kek"); //displayed text is value of starttime (30000) - current value of timer,
} //some sort of reaction game thing
@Override
public void onFinish() {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView scoreText = (TextView) findViewById(R.id.scoreText);
Button startStopButton = (Button) findViewById(R.id.startStopButton);
startStopButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!buttonClicked) {
timer.start();
buttonClicked = true;
}
else {
timer.cancel();
buttonClicked = false;
}
}
});
}
}
修改
如何在行scoreText.setText(startTime - millisUntilFinished);
中以正确的方式显示startTime-current定时器值?
CountDownTimer timer = new CountDownTimer(startTime,interval){
@Override
public void onTick(long millisUntilFinished) {
scoreText.setText(startTime - millisUntilFinished);
}
@Override
public void onFinish() {
}
};
答案 0 :(得分:0)
实际上,您要宣布fn
day2
(input: string): uint = let
val
[n:int]
input = g1ofg0(input)
val n0 = strlen(input)
val n0 = sz2i(n0) // int(n)
fun
nextindex
(
i: natLt(n)
) : natLt(n) = nmod(i + n0/2, n0)
fun
loop(i: natLte(n), acc: uint): uint =
if i >= n0 then acc else
(
if input[i] = input[nextindex(i)]
then loop(i+1, acc + digit2uint(input[i]))
else loop(i+1, acc)
)
in
loop(0, 0u)
end // end of [day2]
两次。一个是全球性的,另一个是当地的。您可以替换TextView scoreText
到TextView scoreText = (TextView) findViewById(R.id.scoreText);
在你的onCreate()