码迷,mamicode.com
首页 > 其他好文 > 详细

使用AlertDialog中的视图绑定时遇到的异常

时间:2015-02-06 21:46:15      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

在创建自定义对话框时,我们会给这个对话框设置一个View

dialog = new AlertDialog.Builder(this).setView(layout).create();

但是当我们需要复用这个layout视图的时候,如果不做处理直接把layout设置到其他控件会出现异常,原因是作为子视图的layout只能归属于某一个父元素。要想复用,必须在父元素中移除layout

ViewGroup Vparent = (ViewGroup) layout.getParent();
if(Vparent!=null){
  Vparent.removeAllViewsInLayout();
}

这样就可以在其他控件中再次使用layout,同时layout中的数据也可以保留下来

使用AlertDialog中的视图绑定时遇到的异常

标签:

原文地址:http://www.cnblogs.com/coder-gosling/p/4277946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!