有人在这个循环中看到我的错误吗?

时间:2013-11-07 23:29:35

标签: java android for-loop view textview

我试图用textViews制作列表。它的工作原理就像我想要的那样,除了由于某种原因i = 0和i = 1都写在同一个地方。 所以我的问题只是关于他们的立场。我不明白为什么i = 1不低于i = 0。别人看到了吗?

public class See extends Activity {
RelativeLayout rl;
List<TextView>listFR  = new ArrayList<TextView>();
List<TextView>listDE  = new ArrayList<TextView>();
List<RelativeLayout.LayoutParams> FRParams = new ArrayList<RelativeLayout.LayoutParams>();
List<RelativeLayout.LayoutParams> DEParams = new ArrayList<RelativeLayout.LayoutParams>();



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_see);
    Tree t = new Tree("T1");
    rl = (RelativeLayout)findViewById(R.id.rLayout);




    for(int i = 0;i<t.getSize();i++){

        FRParams.add(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        DEParams.add(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        FRParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        DEParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        if(i!=0){

        FRParams.get(i).addRule(RelativeLayout.BELOW, listFR.get(i - 1).getId());
        DEParams.get(i).addRule(RelativeLayout.BELOW, listDE.get(i - 1).getId()); 

        } else {

            FRParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_TOP);
            DEParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_TOP);
        }

        listFR.add(new TextView(See.this));
        listDE.add(new TextView(See.this));     
        listFR.get(i).setTextAppearance(See.this, android.R.style.TextAppearance_DeviceDefault);
        listDE.get(i).setTextAppearance(See.this, android.R.style.TextAppearance_DeviceDefault);
        listFR.get(i).setText(t.getLeaf(i).getFR());
        listDE.get(i).setText(t.getLeaf(i).getDE());
        listFR.get(i).setId(i);
        listDE.get(i).setId(i); 

        rl.addView(listFR.get(i), FRParams.get(i));
        rl.addView(listDE.get(i), DEParams.get(i)); 

    } 

}

}

0 个答案:

没有答案