我在 sqlite 中有某些数据,每次单击“保存”按钮时它都会更新,并且我想将数据显示到表布局中,以便为更新的数据添加更多行。
我有某些代码,但它仅显示更新的数据替换以前的数据,并且我想在数据更新时添加更多行。
我知道这只是在表格布局中添加一行,但如何添加更多行?
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));
这是我经过一番尝试和错误后发现的技术,它允许您保留 XML 样式并避免使用<merge/>
(即 inflate() 需要合并才能附加到根,并返回根节点)。无运行时间new TableRow()
s or new TextView()
是必需的。
Code
注:这里CheckBalanceActivity
是一些样本Activity
class
TableLayout table = (TableLayout)CheckBalanceActivity.this.findViewById(R.id.attrib_table);
for(ResourceBalance b : xmlDoc.balance_info)
{
// Inflate your row "template" and fill out the fields.
TableRow row = (TableRow)LayoutInflater.from(CheckBalanceActivity.this).inflate(R.layout.attrib_row, null);
((TextView)row.findViewById(R.id.attrib_name)).setText(b.NAME);
((TextView)row.findViewById(R.id.attrib_value)).setText(b.VALUE);
table.addView(row);
}
table.requestLayout(); // Not sure if this is needed.
attrib_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TableRow style="@style/PlanAttribute" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
style="@style/PlanAttributeText"
android:id="@+id/attrib_name"
android:textStyle="bold"/>
<TextView
style="@style/PlanAttributeText"
android:id="@+id/attrib_value"
android:gravity="right"
android:textStyle="normal"/>
</TableRow>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)