gpt4 book ai didi

java - 如何循环此语句,将 3 个更改值设置为 40 个文本字段的 setText?

转载 作者:行者123 更新时间:2023-12-02 10:39:32 25 4
gpt4 key购买 nike

这是我没有存储在列表中时的代码。这得到了我想要在不同文本字段中显示的内容,但我希望它更短,所以我想循环它。

//“answerStoration.retrieveDataChoices(i,TB)”是来自其他类的函数,返回数组列表;

quizAnswer1store.setText(answerStoration.retrieveDataChoices(1,TB).get(0));
quizAnswer2store.setText(answerStoration.retrieveDataChoices(1,TB).get(1));
quizAnswer3store.setText(answerStoration.retrieveDataChoices(1,TB).get(2));
quizAnswer4store.setText(answerStoration.retrieveDataChoices(1,TB).get(3));
quizAnswer1store2.setText(answerStoration.retrieveDataChoices(2,TB).get(0));
quizAnswer2store2.setText(answerStoration.retrieveDataChoices(2,TB).get(1));
quizAnswer3store2.setText(answerStoration.retrieveDataChoices(2,TB).get(2));
quizAnswer4store2.setText(answerStoration.retrieveDataChoices(2,TB).get(3));
quizAnswer1store3.setText(answerStoration.retrieveDataChoices(3,TB).get(0));
quizAnswer2store3.setText(answerStoration.retrieveDataChoices(3,TB).get(1));
quizAnswer3store3.setText(answerStoration.retrieveDataChoices(3,TB).get(2));
quizAnswer4store3.setText(answerStoration.retrieveDataChoices(3,TB).get(3));

我将其存储在列表“quizAnswerSTORE”中,我尝试循环但不起作用。

int k = 0;
for(int i = 0; i<quizAnswerSTORE.size(); i++){
for(int j = 1; j < 11; j++){
while(k<4){
quizAnswerSTORE.get(i).setText(answerStoration.retrieveDataChoices(j,TB).get(k));
}
}
}

预期结果是在不同的 40 个文本字段中显示数据库中的不同值。因为每次循环值递增时,它都会使用不同的值滚动浏览我的数据库。 J变量代表我的数据库中的id。 K 是从四列数据库中retrieveDataAnswers 函数返回的arrayList 中获取的值的索引。

给你。我希望你能解决这个问题。

最佳答案

您可以使用 mod 来控制最大 int 值,例如 i % 10 不能接受超过 10 的值。

示例:

public class Main {
public static void main(String[] args) {
int j = 1;
int k = 0;


for(int i = 0; i < 40; i++) {

System.out.println("quizAnswerSTORE"+i+".setText(answerStoration.retrieveDataChoices("+j+",TB).get("+k+"));");
k = (k + 1)%4;

if( k == 0) {
j = (j+1) % 11;
}

}

}
}

输出:

quizAnswerSTORE0.setText(answerStoration.retrieveDataChoices(1,TB).get(0));
quizAnswerSTORE1.setText(answerStoration.retrieveDataChoices(1,TB).get(1));
quizAnswerSTORE2.setText(answerStoration.retrieveDataChoices(1,TB).get(2));
quizAnswerSTORE3.setText(answerStoration.retrieveDataChoices(1,TB).get(3));
quizAnswerSTORE4.setText(answerStoration.retrieveDataChoices(2,TB).get(0));
quizAnswerSTORE5.setText(answerStoration.retrieveDataChoices(2,TB).get(1));
quizAnswerSTORE6.setText(answerStoration.retrieveDataChoices(2,TB).get(2));
quizAnswerSTORE7.setText(answerStoration.retrieveDataChoices(2,TB).get(3));
quizAnswerSTORE8.setText(answerStoration.retrieveDataChoices(3,TB).get(0));
quizAnswerSTORE9.setText(answerStoration.retrieveDataChoices(3,TB).get(1));
quizAnswerSTORE10.setText(answerStoration.retrieveDataChoices(3,TB).get(2));
quizAnswerSTORE11.setText(answerStoration.retrieveDataChoices(3,TB).get(3));
...
quizAnswerSTORE38.setText(answerStoration.retrieveDataChoices(10,TB).get(2));
quizAnswerSTORE39.setText(answerStoration.retrieveDataChoices(10,TB).get(3));

关于java - 如何循环此语句,将 3 个更改值设置为 40 个文本字段的 setText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53029047/

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