如何动态地添加行到表布局 [英] How to add rows dynamically into table layout

查看:138
本文介绍了如何动态地添加行到表布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sqllite一定的数据,并随时更新,我点击Save按钮,每一次,我想显示数据到表布局更新的data.I增加更多的行具有一定的code,但它展示只有更新的数据替换previous的数据,我想添加更多行的数据更新。我知道这仅仅是添加一行到表格的布局,但我如何添加更多的行。

  TableLayout TL =(TableLayout)findViewById(R.id.maintable);
的TableRow TR1 =新的TableRow(本);
tr1.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView中的TextView =新的TextView(本);
textview.setText(数据);
//textview.getTextColors(R.color。)
textview.setTextColor(Color.YELLOW);
tr1.addView(TextView的);
tl.addView(TR1,新TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
 

解决方案

您已经添加一行到表格的布局,你可以添加多个的TableRow 实例进路的 tableLayout 对象

  tl.addView(ROW1);
tl.addView(ROW2);
 

等等...

I have certain data in sqllite and it update every time whenever, I click on save button and i want to show the data into a table layout for adding more rows for updated data.I have certain code but it show only the updated data replacing previous data and i want to add more rows as the data updated. I know this is only to add one row into table layout but how can i add more rows.

TableLayout tl=(TableLayout)findViewById(R.id.maintable);    
TableRow tr1 = new TableRow(this);
tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView textview = new TextView(this);
textview.setText(data);
//textview.getTextColors(R.color.)
textview.setTextColor(Color.YELLOW);
tr1.addView(textview);
tl.addView(tr1, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

解决方案

The way you have added a row into the table layout you can add multiple TableRow instances into your tableLayout object

tl.addView(row1);
tl.addView(row2);

etc...

这篇关于如何动态地添加行到表布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆