我想在linear layout上动态的添加textviews 数组,然后定义为一个公共变量。当我运行程序时,当进入循环语句时程序就强行关闭了。
LinearLayout myLayout = (LinearLayout) findViewById(R.id.my_layout);
LayoutParams lp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
pairs=new TextView[num_match+1];
for(int l=1;l<=num_match;l++)
{
pairs[l].setTextSize(15);
pairs[l].setLayoutParams(lp);
pairs[l].setId(l);
pairs[l].setText(m1[l]+" - "+m2[l]);
myLayout.addView(pairs[l]);
}