如何解决如何以编程方式动态更新Android中表行的序列号?
我正在将序列号动态添加到表行中。我在创建的每一行上都有一个清除按钮。用户,如果清除之间的一行[例如清除5个表行之间的3,则它看起来像1、2、4、5]而是我要求将之前的行的序列号重置为串行。需要帮助!
private void init() {
syy = (TableLayout) findViewById(R.id.scantable);
if (data.getText().toString().trim().length() > 0) {
TableRow tbrow = new TableRow(getApplicationContext());
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams();
int leftMargin = 0;
int topMargin = 1;
int rightMargin = 0;
int bottomMargin = 1;
tableRowParams.setMargins(leftMargin,topMargin,rightMargin,bottomMargin);
tbrow.setLayoutParams(tableRowParams);
TextView sno = new TextView(this);
sno.setText(" " + (isno) + " ");
sno.setTextColor(Color.WHITE);
clearbutton = new Button(getApplicationContext());
clearbutton.setText("CLEAR");
clearbutton.setTextColor(Color.DKGRAY);
clearbutton.setBackgroundColor(Color.parseColor("#FFBF00"));
clearbutton.setPadding(0,2,2);
clearbutton.setLayoutParams(new TableRow.LayoutParams(90,40));
clearbutton.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View row = (View) v.getParent();
ViewGroup container = ((ViewGroup) row.getParent());
container.removeView(row);
container.invalidate();
rowcount++;
isno--;
scandisplay.setText("" + rowcount); ////Clear a row will increase the scans left.
scanButton.setVisibility(View.VISIBLE);
if (tablerows != 0) {
tablerows--;
}
////// Help with this Line of code.
for(int k=1;k<=syy.getChildCount();k++)
{
View view = syy.getChildAt(k);
TableRow r = (TableRow) view;
TextView rowdata = (TextView) r.getChildAt(0);
rowdata.setText(k);
syy.addView(rowdata,k);
}
///////////////////////
}
});
if (!sno.getText().toString().trim().equals("")) {
tbrow.addView(sno);
tbrow.addView(t2v);
tbrow.addView(clearbutton);
syy.addView(tbrow);
isno++;
rowcount--;
}
else {
syy.removeView(tbrow);
rowcount--;
rowcount++; // not needed but to maintain the rowcount.
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。