【发布时间】:2014-07-10 16:56:00
【问题描述】:
我正在开发一个 android 应用程序,我需要在事件发生时刷新表格。也就是说,当用户单击按钮时,表格现在应该更改显示新数据。所以我为此目的使用了 removeAllViews 。然后,我将动态地将行添加到表中。发生的情况是,当行数少于先前的行数时,将显示新行,在它们下方,还会显示旧行。你能告诉我需要做什么吗?
TableLayout tableLayout1;
public void displayPanel1(int co) // dynamically add table
{
LinearLayout ll = (LinearLayout)findViewById(R.id.asdf);
LayoutParams lp = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
for(int i=0;i<co;i++) {
TableRow tR = new TableRow(this);
for(int j=0;j<12;j++) {
TextView tv2=new TextView(this);
tv2.setText(i+j+""+"\n"+"h");
tR.addView(tv2);
}
tableLayout1.addView(tR);
}
ll.addView(tableLayout1, lp);
}
在点击事件中我写了 tableLayout1.removeAllViews();并再次调用 displayPanel() 函数
【问题讨论】:
-
你能告诉我们一些相关的代码吗?没有看到你在做什么,我们只能猜测问题可能是什么。
-
你在使用任何主题吗??尝试使您的布局无效。
-
我没有使用任何主题。我也尝试过无效..但它仍然不起作用:(
-
请格式化您的代码。
标签: android android-tablelayout