且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Android的表格布局动态删除行

更新时间:2023-12-04 13:53:18

的onClick按钮会给你点击视图,你的情况的按钮。该按钮的父母是要删除的行。删除该行从它的父将摆脱它。

onClick on the button will give you the clicked view, the button in your case. That button's parent is the row you want to delete. Deleting that row from it's parent will get rid of it.

你如何实现这样的一个例子:

An example of how you could implement this:

    button.setOnClickListener(new OnClickListener()
    {
        @Override public void onClick(View v)
        {
            // row is your row, the parent of the clicked button
            View row = (View) v.getParent();
            // container contains all the rows, you could keep a variable somewhere else to the container which you can refer to here
            ViewGroup container = ((ViewGroup)row.getParent());
            // delete the row and invalidate your view so it gets redrawn
            container.removeView(row);
            container.invalidate();
        }
    });