有一个问题,从LinearLayout中编程去除TextViews [英] Having a problem removing TextViews from a LinearLayout programmatically

查看:234
本文介绍了有一个问题,从LinearLayout中编程去除TextViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程方式添加TextViews到的LinearLayout,并删除他们联系。这一切工作正常,只是当最后的TextView被触摸它不会删除。如果我做任何事情一样摆脱键盘或向下滚动,在所有的屏幕上,最后的TextView将被删除,这让我觉得这是一个刷新的问题,但我不知道如何解决。

下面是一些我使用的是code:

 最后的TextView TV1 =新的TextView(本);
tv1.setText(测试);

tv1.setOnClickListener(新View.OnClickListener(){

    @覆盖
    公共无效的onClick(视图v){

        linearlayout1.removeView(TV1);

    }
});
 

我也加入了这个code在设法解决这个问题,但它并没有改变什么:

 如果(linearlayout1.getChildCount()== 1){
    linearlayout1.removeAllViewsInLayout();
}
 

解决方案

这听起来更在Android中的一个错误,但有一件事你可以尝试是清除隐藏在你的TextView tv1.setVisibility(查看。 GONE)。或者你也可以添加 linearlayout1.invalidate()拆除的最后一个项目后触发重绘。

I am programmatically adding TextViews to a LinearLayout, and deleting them on touch. It all works fine except when the last TextView is touched it doesn't get removed. If I do anything else on the screen like get rid of the keyboard or scroll down at all, the last TextView will be deleted, which makes me think it's a refresh problem, but I have no idea how to solve that.

Here's some of the code I'm using:

final TextView tv1 = new TextView(this);
tv1.setText("Test");

tv1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

        linearlayout1.removeView(tv1);

    }
});

I have also added this code in to try to solve the problem but it didn't change anything:

if (linearlayout1.getChildCount() == 1) {
    linearlayout1.removeAllViewsInLayout();
}

解决方案

This sounds more of a bug in Android, but one thing you could try is hiding your TextView before removal tv1.setVisibility(View.GONE). Or alternatively you could add linearlayout1.invalidate() after removal of the last item to trigger redrawing.

这篇关于有一个问题,从LinearLayout中编程去除TextViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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