从Android的表格布局动态删除行 [英] Delete row dynamically from table layout in android

查看:394
本文介绍了从Android的表格布局动态删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TableLayout 对此我动态添加行。在每一行的有2个因素,其中之一就是的TextView 另一种是按钮。当我点击按钮,这是在连续present,该行应删除。这怎么能在Android的办呢?如何找到ROWID以及如何动态删除一行。谁能帮我整理出这个问题。

I am having a TableLayout for which I added rows dynamically. In each of the row there are 2 elements of which one is TextView other is Button. When I click the button that is present in a row, that row should be deleted. How can this be done in Android ? How to find rowid and how to delete a row dynamically. Can anyone help me in sorting out this issue.

推荐答案

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

这篇关于从Android的表格布局动态删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆