我编写了这段代码,它应该在每个整数(0-4)处显示不同的文本。 If语句0-3很好,但当整数变为4时,TextView不会更改为“Example 5”。如果按下按钮没有任何反应,我不知道为什么!需要帮助;)
package com.eastereggdevelopment.entwederoder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import java.util.Random;
public class Start extends AppCompatActivity {
private int question;
private TextView Question;
private TextView quNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
}
public void back(View view)
{
if(question > 1)
{
question--;
setQuestion();
}
}
public void next(View view)
{
if(question < 5)
{
question++;
setQuestion();
}
}
public void rumble(View view)
{
Random rand = new Random();
question = (rand.nextInt(4));
setQuestion();
}
public void setQuestion()
{
TextView Question = (TextView) findViewById(R.id.question);
if(question == 0)
{
Question.setText("Example 1");
}
if(question == 1)
{
Question.setText("Example 2");
}
if(question == 2)
{
Question.setText("Example 3");
}
if(question == 3)
{
Question.setText("Example 4");
}
if(question == 4)
{
Question.setText("Example 5");
}
}
}
谢谢:)
答案 0 :(得分:2)
这一行 - mysqli
,将值更改为5
nextInt(int n)方法用于获取伪随机,均匀分布的int值介于0(包含)和指定值(独占)之间,取自这个随机数生成器的序列。
<强> Java Documentation 强>