如何以编程方式动态更新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 (将#修改为@)