如何在android中的表格布局中删除表格行
void init()
{
intcolumnwidth1 = int_scr_wd*55;
intcolumnwidth1 = intcolumnwidth1/100;
for (int i = 0; i < strarr.length-1; i++)
{
strinarr = fun1.split(strarr[i].trim(),"^");
tr1 = (TableRow) new TableRow(this);
txt1=new TextView(this);
txt1.setWidth(intcolumnwidth1);
txt1.setText(strinarr[0]);
tr1.addView(txt1);
tl.addView(tr1,new TableLayout.LayoutParams(layoutParams));
}
}
场景是这样的,当我第一次打开此页面时,它会在表布局中动态添加行...但是如果一段时间后数据库中的数据发生变化...当我单击刷新按钮时,它将在旧数据之后附加新数据表格布局...我需要的只是如何刷新或删除表格布局中已存在的文本视图的解决方案...
谢谢..
void init()
{
intcolumnwidth1 = int_scr_wd*55;
intcolumnwidth1 = intcolumnwidth1/100;
for (int i = 0; i < strarr.length-1; i++)
{
strinarr = fun1.split(strarr[i].trim(),"^");
tr1 = (TableRow) new TableRow(this);
txt1=new TextView(this);
txt1.setWidth(intcolumnwidth1);
txt1.setText(strinarr[0]);
tr1.addView(txt1);
tl.addView(tr1,new TableLayout.LayoutParams(layoutParams));
}
}
Scenario is this when for the first i open this page it dynamically adds rows in the table layout ... but if after some time data in database changes ... when i click on refresh button it appends the new data after the old data in the table layout... all i need is the solution for how to refresh or delete textview that already exists in the table layout...
thanx..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
尝试 removeView
Try removeView
我编写的这个方法会删除除第一行之外的所有行。如果您不想删除标题行,那么它很有用,例如:
This method I have written removes all rows except the first one. It is useful if you don't want to remove the header row, for example:
我意识到这是一个旧线程,但当我遇到这个问题却没有一个像样的答案时,我感到震惊。
我这样做:
这将删除所有子视图,在本例中为行和所有内容。根据您的描述,您似乎不想只删除一行,而是想删除它们,然后再次加载行。上面的代码将完成删除部分。
I realize this is a old thread but I as shocked when I came across this without a decent answer.
I do it like this:
That will remove all of the child views, in this case rows and everything. It doesn't seem by your description that you want to delete just one row, but that you want to remove them and then load the rows again. The above code will do the removing part.
其他解决方案要求您的行具有唯一的 ID。
如果它们没有唯一的 id 那么如何使用:
无论如何,您应该尝试学习如何使用 SimpleCursorAdapter 或 CursorAdapter 因为它们是专门设计用于在列表中显示数据库查询的内容。请参阅使用 AdapterView 绑定到数据。
The other solutions require your rows to have unique ids.
If they don't have unique ids then how about using:
In any case, you should try learning how to use SimpleCursorAdapter or CursorAdapter because they are specifically designed for displaying the content of a database query in a list. See Binding to Data with AdapterView.
您需要知道要删除的文本视图。可以通过使用 setId() 设置唯一 id 或使用 setTag() 使用唯一标签来识别 TextView。
然后可以通过 TextView tv = (TextView) tr1.findViewByTag(unique tag); 来识别。
使用removeView删除视图。
You need to know the textview to be deleted. The TextView can be identified by setting a unique id using setId() or using a unique tag using setTag().
It can then be identified by TextView tv = (TextView) tr1.findViewByTag(unique tag);
Use removeView to delete the View.
我用这个:
I use this:
查看此代码以删除表中的行
look this code to remove row in table
使用这个:
其中 i - 是您要删除的行位置。
Use this:
Where i - is row position, wich you want to delete.