【问题标题】:tablelayout delete tablerow in androidandroid中的tablelayout删除tablerow
【发布时间】:2012-05-17 23:03:39
【问题描述】:
    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));

** 我想删除 bu.setOnClickListener 中的 tablerow 怎么做 removeViewAt() ,我找不到 indexId **

【问题讨论】:

    标签: android tablelayout tablerow


    【解决方案1】:

    使用removeView 删除表行:

    table.removeView(row);
    

    注意:如果他们没有唯一 ID,则使用:

    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); 
        } 
    } 
    

    【讨论】:

    • TableRow 行 = 新 TableRow(this);添加final,成为final TableRow row = new TableRow(this);这行得通!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-04-22
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多