本文介绍了tablelayout删除tablerow的android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    final TableLayout table = (TableLayout) findViewById(R.id.tableLayout);
    TableRow row = new TableRow(this);


    TextView t2 = new TextView(this);
    t2.setText("test");
    row.addView(t2);

    Button bu = new Button(this);
    bu.setBackgroundResource(R.drawable.del);
    bu.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {

            //I need to delete the tablerow
                            //how to do?

        }

    });
    row.addView(bu);

    table.addView(row, new TableLayout.LayoutParams(WC, WC));

**我想删除的TableRow在bu.setOnClickListener怎么办removeViewAt(),我找不到IndexID为**

**i want to delete tablerow in bu.setOnClickListenerhow to do removeViewAt() ,i cant find indexId**

推荐答案

使用 removeView 以去掉tablerow的:

use removeView for removing tablerow as:

table.removeView(row);

注意::如果他们不具有唯一的ID,然后使用:

NOTE: If they don't have unique id then use:

table.removeView(rowIndex);

和使用 removeViewAt

for(int i = 0, j < table.getChildCount(); i < j; i++){
    // then, you can remove the the row you want...
    // for instance...
    TableRow row = getChildAt(i);
    if( something you want to check ) {
        removeViewAt(i);
        // or...
        removeView(row);
    }
}

这篇关于tablelayout删除tablerow的android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:39