如何在Android Studio的Java中为TextView指定问题?

huangapple 未分类评论47阅读模式
英文:

How to specify the question to the textview in android studio java?

问题

以下是翻译好的内容:

这是我的随机问题并且我有一个问题需要检测哪个问题应该在 TextView 中。所以我必须指定,如果是这个问题,那么多个选择将会被显示。这是我的代码:

这是我的问题:

Random r = new Random();

String [] quest = {"在以下字母序列中,从右边数第 8 个字母的左边第 14 个字母是哪个字母?" +
        "A O B P C Q D R E S F T G U H V I W J X K Y L Z M N。", "Hritik 比 Salman 高,而 Salman 比 Sanjay 矮。Akshay 比" +
        "Shahrukh 高,但比 Salman 矮。Sanjay 比 Hritik 矮。谁最高?", "Lali 和 Anju 是一对已婚夫妻。Tunu 和 Munu 是兄弟。Tunu 是 Lali 的兄弟。Munu 与 Anju 的关系是什么?",
        "在单词 'WRISTWATCH' 中,有多少组两个字母的字母,它们之间的字母与英文字母顺序中的字母数相同。"};

boolean [] usedIndices = new boolean[quest.length];

这是我的主要代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_easy);

    Button question = findViewById(R.id.btnQuestion);
    final Button answer = findViewById(R.id.btnAnswer);
    final TextView ask = findViewById(R.id.txtAsk);

    question.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            answer.setVisibility(View.VISIBLE);
            QuestionCount QC = new QuestionCount();
            int indextoBeUsed;
            do {
                indextoBeUsed = r.nextInt(quest.length);
            }
            while (usedIndices[indextoBeUsed]);
            usedIndices[indextoBeUsed] = true;
            ask.setText(quest[indextoBeUsed]);
            count += 1;

            if (ask.getText().toString().equals("在以下字母序列中,从右边数第 8 个字母的左边第 14 个字母是哪个字母?")) { // 这部分我遇到了一个错误。例如,如果这个问题出现在 TextView 中,正确的多个选择将会显示在按钮上。

            }
        }
    });
}
英文:

I have a random question and I have a problem detecting which question should be in the TextView of course. So I have to specify that if this question, the multiple choices will be shown. This is my code:

This is my question:

Random r = new Random();

String [] quest = {"Which alphabet will be 14th to the left of 8th alphabet from the right in the following series of letters?" +
        "A O B P C Q D R E S F T G U H V I W J X K Y L Z M N.", "Hritik is taller than Salman who is shorter than Sanjay. Akshay is taller than " +
        "Shahrukh but shorter than Salman. Sanjay is shorter than Hritik. Who is the tallest?" , "Lali and Anju are a married couple. Tunu and Munu " +
        "are brothers. Tunu is the brother of Lali. How is Munu related to Anju?", "How many sets of two letters have as many letters " +
        "between them as in the English alphabetical order in the word WRISTWATCH."};

boolean [] usedIndices = new boolean[quest.length];  

This are my main code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_easy);

    Button question = findViewById(R.id.btnQuestion);
    final Button answer = findViewById(R.id.btnAnswer);
    final TextView ask = findViewById(R.id.txtAsk);

    question.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            answer.setVisibility(View.VISIBLE);
            QuestionCount QC = new QuestionCount();
            int indextoBeUsed;
            do {
                indextoBeUsed = r.nextInt(quest.length);
            }
            while (usedIndices[indextoBeUsed]);
            usedIndices[indextoBeUsed] = true;
            ask.setText(quest[indextoBeUsed]);
            count += 1;

            if (ask.setText("Which alphabet will be 14th to the left of 8th alphabet from the right in the following series of letters?")) { // This part I got an error. For example, if this question appeared in the textview, the right multiple choices will be shown in the buttons.

            }
        }
    });
}

huangapple
  • 本文由 发表于 2020年4月7日 12:52:45
  • 转载请务必保留本文链接:https://java.coder-hub.com/61073048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定