gpt4 book ai didi

java - 正确答案进度条

转载 作者:行者123 更新时间:2023-12-01 09:10:44 24 4
gpt4 key购买 nike

我正在 android studio 中做一个小数学游戏,从第一级开始,玩家需要连续回答 10 个问题。我会计算分数,当玩家获得一定分数时,他们就会进入另一个级别。我想添加一个进度条,随着正确答案的进展。所以说,当玩家需要连续 10 个正确答案但只有 5 个时,它将被填充 50% 等。这是计算分数的代码:

  Button answerButton = (Button) findViewById(R.id.answerButton);
answerButton.setOnClickListener(new View.OnClickListener(){
@Override

public void onClick(View v) {
try{
answerUser = Integer.parseInt(numberEdit.getText().toString());
}
catch (NumberFormatException e)
{
answerUser = 0;
Toast.makeText(context,
"Error, masdaohfisahfi9aw",
Toast.LENGTH_SHORT).show();
}
if(answer == answerUser)
{
TextView Scores = (TextView) findViewById(R.id.scoreText);
score ++;

String String3 = String.valueOf(score);
Scores.setText(String3);
answerText.setText("Well done!");
do {
Random rand = new Random();
Random rand1 = new Random();
number = rand.nextInt(10) + 1;
numbers1 = rand1.nextInt(10) + 1;
TextView number1 = (TextView) findViewById(R.id.number1);
TextView number2 = (TextView) findViewById(R.id.number2);

String String1 = String.valueOf(number);
String String2 = String.valueOf(numbers1);
number1.setText(String1);
number2.setText(String2);
answer = number + numbers1;
answerUser = 0;
numberEdit.setText("");

}

while(answer==answerUser);
if(score == 10)
{
alert();
}
}
else
{
answerText.setText("Wrong");
TextView Scores = (TextView) findViewById(R.id.scoreText);
score = 0;
String String3 = String.valueOf(score);
Scores.setText(String3);
}
}

});

最佳答案

在你的类(class):

ProgressBar progressBar

在你的 onCreate 中:

 progressBar = (ProgressBar) findViewById(R.id.answerProgress);
progressBar.setMax(10);
progressBar.setProgress(0);

然后在这部分代码中

 if(answer == answerUser)
{
TextView Scores = (TextView) findViewById(R.id.scoreText);
score ++;
progressBar.setProgress(score);
....
}

在 XML 中,指定您想要一个水平进度条,否则它将是圆形的:

<ProgressBar
android:layout_width="match_parent"
android:layout_height="50dp"
style="@android:style/Widget.Holo.ProgressBar.Horizontal"
android:id="@+id/answerProgress"
/>

关于java - 正确答案进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com