我有一个带有12个linearlayout的viewflipper(子视图)。这些Linearlayout被赋予id,如jan,feb,mar,...等等。现在,我希望以编程方式在每个布局中添加textview。我怎么做?这是我的代码。它也没有给出任何错误,也没有显示文本视图。
LinearLayout jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec;
jan = (LinearLayout)findViewById(R.id.jan);
feb = (LinearLayout)findViewById(R.id.feb);
mar = (LinearLayout)findViewById(R.id.mar);
//and so on...for all 12 months
//inside onCreate
for(int a=0;a<12;a++){
TextView txt = new TextView(TimelineActivity.this);
txt.setText("month : " + (a+1));
txt.setTextColor(0xadadad);
switch(a){
case 0:
jan.addView(txt);
break;
case 1:
feb.addView(txt);
break;
case 2:
mar.addView(txt);
break;
case 3:
apr.addView(txt);
break;
case 4:
may.addView(txt);
break;
case 5:
jun.addView(txt);
break;
case 6:
jul.addView(txt);
break;
case 7:
aug.addView(txt);
break;
case 8:
sep.addView(txt);
break;
case 9:
oct.addView(txt);
break;
case 10:
nov.addView(txt);
break;
case 11:
dec.addView(txt);
break;
}
我确信这很简单,我犯了一些愚蠢的错误,但无法弄清楚是什么......