道路规则应用程序我有一个活动,其中将根据票号显示问题和答案(20 个问题和 5x20 个答案)。字符串中包含的问题和答案重新排序并排序。我的代码非常糟糕,我想通过循环来简化,就像有问题 [q] 但有 2 个变量的情况一样。请帮帮我。https://play.google.com/store/apps/details?id=ua.in.sil.cryzalit.mybiletsnumber = intent.getStringExtra("number"); for( int i = 1; i < 21; i++) { q[i]= this.getResources().getIdentifier("q"+i+"_" + number, "string", this.getPackageName()); } int a1_1 = this.getResources().getIdentifier("a1_1_" + number, "string", this.getPackageName()); int a2_1 = this.getResources().getIdentifier("a2_1_" + number, "string", this.getPackageName()); int a3_1 = this.getResources().getIdentifier("a3_1_" + number, "string", this.getPackageName()); int a4_1 = this.getResources().getIdentifier("a4_1_" + number, "string", this.getPackageName()); int a5_1 = this.getResources().getIdentifier("a5_1_" + number, "string", this.getPackageName());\\\\ int a1_20 = this.getResources().getIdentifier("a1_20_" + number, "string", this.getPackageName()); int a2_20 = this.getResources().getIdentifier("a2_20_" + number, "string", this.getPackageName()); int a3_20 = this.getResources().getIdentifier("a3_20_" + number, "string", this.getPackageName()); int a4_20 = this.getResources().getIdentifier("a4_20_" + number, "string", this.getPackageName()); int a5_20 = this.getResources().getIdentifier("a5_20_" + number, "string", this.getPackageName());
1 回答
FFIVE
TA贡献1797条经验 获得超6个赞
可以使用二维数组,代码如下:
int answers[][] = new int[20][5];
for( int i = 0; i < 20; i++) {
for( int j = 0; j < 5; j++){
answers[i][j] = this.getResources().getIdentifier("a"+(j+1)+"_"+(i+1)_" + number, "string", this.getPackageName());
}
}
我也不确定q数组,因为它将从 0 开始,只需重新访问它即可。
添加回答
举报
0/150
提交
取消