添加和删​​除在Android的动态视图? [英] Add and Remove Views in Android Dynamically?

查看:106
本文介绍了添加和删​​除在Android的动态视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加和删除的意见,如的TextView - 从Android应用程序像原来的股票Android的联系人屏幕上,您preSS右侧的小图标现场的一侧,并将其添加或删除它由的TextView editTextView (从我可以现场见)。

How do I add and remove views such as TextViews from Android app like on the original stock Android contacts screen where you press a small icon on the right side of a field and it adds or deletes a field which consists of a TextView and an editTextView (from what I can see).

这是如何实现这一点任何的例子吗?

Any examples on how to achieve this?

推荐答案

从<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/962a61e33f4b9c50?pli=1">this螺纹对Android的开发者来说,接缝的ViewParent和的ViewGroup,一般无法删除的意见。你需要转换你的父母到布局(如果它是一个布局)来完成你想要的东西。

From this thread on android-developers, it seams that ViewParent and ViewGroup in general can't remove views. You need to cast your parent to a layout (if it is a layout) to accomplish what you want.

例如:

View namebar = view.findViewById(R.id.namebar);
((ViewGroup) namebar.getParent()).removeView(namebar);

这篇关于添加和删​​除在Android的动态视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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