Android使用自定义对话框报错:The specified child already has a parent. You must call removeView() on the...
来源:互联网 发布:excel拆分数据公式 编辑:程序博客网 时间:2024/05/29 21:30
今天实现了一个自定义对话框,当点击相应按钮时弹出该对话框。在测试过程中发现,第一次点击按钮时,对话框可以正常出现,但是在点击对话框上的“确定”或“取消”按钮回到主界面后,再次点击按钮,会报错如下:
E/AndroidRuntime(26211): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
出错处的代码为:
- add.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- builder.setTitle("请输入新建相册名");
- builder.setView(linearLayout);
- builder.setPositiveButton("确定",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int which) {
- albumName = (EditText) linearLayout
- .findViewById(R.id.addname);
- String name = albumName.getText().toString();
- System.out.println("用户输入的相册名:" + name);
- }
- });
- builder.setNegativeButton("取消",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int which) {
- // TODO Auto-generated method stub
- }
- });
- builder.create().show();
- }
- });
查看代码发现,linearLayout对象是我在oncreate()方法中获得的:
- linearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.dialogname, null);
查明真相之后,只需在监听方法中加上获取linearLayout的语句即可:
- linearLayout = (LinearLayout)getLayoutInflater().inflate(R.layout.dialogname, null);
- builder.setTitle("请输入新建相册名");
- builder.setView(linearLayout); ......
原文:http://blog.csdn.net/lissdy/article/details/8453433
0 0
- Android使用自定义对话框报错:The specified child already has a parent. You must call removeView() on the...
- Android使用自定义对话框报错:The specified child already has a parent. You must call removeView() on the...
- Android使用自定义对话框报错:The specified child already has a parent. You must call removeView() on the...
- . 报错 specified child already has a parent. You must call removeView() on the child's parent first
- 替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's pa
- Android自定义Dialog二次调用报错解决方法:The specified child already has a parent. You must call removeView()
- 自定义Dialog,第二次点击item报The specified child already has a parent. You must call removeView() on the chil
- 总是报The specified child already has a parent. You must call removeView() on the child's parent first.
- 报错:The specified child already has a parent. You must call removeView
- android The specified child already has a parent. You must call removeView() on the child's parent f
- The specified child already has a parent. You must call removeView() on the chil
- The specified child already has a parent. You must call removeView() on the
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's paren
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's paren
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's paren
- Android完美解决The specified child already has a parent. You must call removeView() on the child
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's paren
- Android AlertDialog嵌套及二调用报错解决方法:The specified child already has a parent. You must call removeView()
- 浙大 pat Basic Level 1023
- ios tableView UITableView中Cell重用机制导致内容重复解决方法
- Timestamp基础知识及时间大小比较
- common-io-2.0的新功能之文件监控FileAlteration(文件监听的两种实现方法《很全的监听文件例子》)
- HeadFirst设计模式--适配器模式
- Android使用自定义对话框报错:The specified child already has a parent. You must call removeView() on the...
- Servlet生命周期
- Struts2的工作原理
- 李某某等强奸案中6名律师被给予行业纪律处分
- mySql 的分页代码怎么写
- IBM Cognos and JavaScript
- 我们的管理:产品经理与程序员协作
- wince6.0 usb功能定制
- 我来了