有关于对话框中放入布局的问题
2013-04-17 14:57
162 查看
The specified child already has a parent. You must call removeView
对于经常看见的removeView()异常,网上的一些方法给出,
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout parent = (LinearLayout) inflater.inflate(R.layout.main, null);
ImageView child = (ImageView)parent.findViewById(R.id.child);
setContentView(parent);
[java] view
plaincopy
把上04row 改为setContentView(child);
并在03row 加入parent.removeView(child);的方法虽然解决了,但是view被over了
在这里我找了一种好办法可以避免出现此种异常。
[java] view
plaincopy
在布局中加入
<com.example.db2.FileBrowser xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/filebrowser" >引入外部xml文件
接下来
fileBrowserView = getLayoutInflater().inflate(R.layout.select_photo,null);
//fileBrowser
fileBrowser = (FileBrowser) fileBrowserView.findViewById(R.id.filebrowser);
fileBrowser.setOnFileBrowserListener(this);
//文件FileBrowser对象已经获得,
alertDialog = new AlertDialog.Builder(this)
.setTitle("选择头像")
.setIcon(R.drawable.select_photo)
.setView(fileBrowserView)
.setPositiveButton("关闭", null)
.create();
alertDialog.show();
即可加载自定义布局。
对于经常看见的removeView()异常,网上的一些方法给出,
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout parent = (LinearLayout) inflater.inflate(R.layout.main, null);
ImageView child = (ImageView)parent.findViewById(R.id.child);
setContentView(parent);
[java] view
plaincopy
把上04row 改为setContentView(child);
并在03row 加入parent.removeView(child);的方法虽然解决了,但是view被over了
在这里我找了一种好办法可以避免出现此种异常。
[java] view
plaincopy
在布局中加入
<com.example.db2.FileBrowser xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/filebrowser" >引入外部xml文件
接下来
fileBrowserView = getLayoutInflater().inflate(R.layout.select_photo,null);
//fileBrowser
fileBrowser = (FileBrowser) fileBrowserView.findViewById(R.id.filebrowser);
fileBrowser.setOnFileBrowserListener(this);
//文件FileBrowser对象已经获得,
alertDialog = new AlertDialog.Builder(this)
.setTitle("选择头像")
.setIcon(R.drawable.select_photo)
.setView(fileBrowserView)
.setPositiveButton("关闭", null)
.create();
alertDialog.show();
即可加载自定义布局。
相关文章推荐
- 关于.Net页面弹出对话框而改变CSS布局的问题
- 关于html CSS 绝对相对布局问题
- 第1章 脸面问题——关于网页布局
- 关于android R.layout 中找不到已存在的布局文件问题的解决
- 关于Eclipse中布局渲染时,不能显示的问题
- 关于css解决俩边等高的问题(等高布局)
- 关于使用 jBox 对话框的提交问题
- Qt: 关于初始化进度对话框会自动弹出的问题
- android关于获取布局宽高的问题
- Android中软键盘弹出时关于布局的问题
- 关于 CFileDialog 对话框多选功能的一个问题
- 关于放入cookie中的中文取出后变乱码的问题及解决办法!
- [轉]关于“网页对话框”中链接和表单提交会在新窗口中打开的问题
- 关于软键盘的遮挡布局问题几点处理
- 坑!!关于通知栏中支持自定义布局,不支持自定义控件的问题
- 【实践】总结(2015/05/07)——关于布局和兼容的一些问题
- 关于Edittext点击弹出软键盘,布局上移标题消失问题,微信聊天界面
- 关于iOS 7当中“编辑”与“新增”按钮的布局问题
- 有关于用css来进行网页布局的一些问题week4
- 问题:关于一个坛友的html布局实现