亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用我的代碼中的 2 個變量創建循環(Android)

使用我的代碼中的 2 個變量創建循環(Android)

慕婉清6462132 2024-01-05 16:53:28
道路規則應用程序我有一個活動,其中將根據票號顯示問題和答案(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 開始,只需重新訪問它即可。


查看完整回答
反對 回復 2024-01-05
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號