2012-05-15 79 views
0

環路錯誤我在我所獲取i ID和ID下顯示所有j值的分配。但我有一個問題:在i第一值j值正常,但在i第二ID j相同的價值即將到來,它顯示在第一ID;它沒有更新。在Java

的代碼片段是:

for (int i = 0; i <= assignment.getValue().size(); i++){ 

     TableRow tr = new TableRow(this); 
     tr.setPadding(2, 2, 2, 2); 

     TableLayout.LayoutParams tableRowParams= 
       new TableLayout.LayoutParams 
       (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.FILL_PARENT); 

     int leftMargin=0; 
     int topMargin=2; 
     int rightMargin=0; 
     int bottomMargin=1; 

     tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); 

     tr.setLayoutParams(tableRowParams); 

     value[i]= new TextView(this); 
     value[i].setText(assignment.getValue().get(i)); 
     System.out.println(value[i].getText().toString()); 
     value[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
     tr.addView(value[i]); 

    for(int j= 0; j < assignment.getScore().size()/assignment.getValue().size(); j++){ 
     scr[i]= new TextView(this); 
      scr[i].setText(categorylist.getScore().get(j)); 
      System.out.println(scr[i].getText().toString()); 
      scr[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
      tr.addView(scr[i]); 
    } t1.addView(tr, tableRowParams); 
+6

請張貼*真正*代碼,而不是你的僞代碼修復。 –

+0

不足以識別問題 –

+3

您的'j'循環不會對'i'或任何派生自外部循環的內容執行操作......因此無論「i」如何都是相同的輸出。事實上,如果你將嵌套的'j'循環移出來以便'獨立',你會得到同樣的結果。 –

回答

0
>>> on i 1st value j values are coming properly but on i 2nd id j same values are coming which it is showing on 1st id. its not updating 

如果我正確理解你的問題,你想擁有Ĵ根據我的工作。但如果我看到你的代碼之間沒有關係我& j。

for(int j= 0; j < assignment.getScore().size()/assignment.getValue().size(); j++){ 
... 
... 
} 

對於第二個循環正常工作,依賴於我(根據你的邏輯)。

+0

@Muuna。 Thanx的答覆。是的,我們正確。但我已經採取了assign.getValue()。size()的大小,我爲它採取了這種方式,並以這種方式採取值scr [i] .setText(categorylist.getScore()。get(j)); – user1395397

+0

我試圖比較我也在許多方面像(int j = 0; j <= i; j ++),但給錯誤數組超出界限的異常。 – user1395397

+0

你得到我在哪裏犯錯? – user1395397

0

assign.getValue()assignment.getScore()和categoryList.getScore()之間存在什麼樣的關係有點不清楚。如果正確地建立了關係,你可能會得到一個更好的答案。

scr [i] .setText(categorylist.getScore()。get(j));

不管 'i' 是什麼你總是設置相同categorylist.getScore()得到(J)到SCR [I],

會像

SCR [I] .setText(所屬分類[I] .getScore()得到(J))可能是您的問題