Android AlertDialog嵌套及二调用报错解决方法:The specified child already has a parent. You must call removeView()
来源:互联网 发布:华为交换机mac绑定 编辑:程序博客网 时间:2024/05/22 01:49
在AlertDialog中重新调用一个AlertDialog时会出现错误:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
出错的代码为:
final LayoutInflater factory2 = LayoutInflater.from(this);
final View textEntryView2 = factory2.inflate(R.layout.findroom,
null);
final AutoCompleteTextView building = (AutoCompleteTextView) textEntryView2
.findViewById(R.id.autoCompleteTextRoom);
// 声明适配器
ArrayAdapter adapter2 = new ArrayAdapter(this,
android.R.layout.simple_dropdown_item_1line, buildingNames);
building.setAdapter(adapter2);
// 下拉列表
final Spinner sp1 = (Spinner) textEntryView2
.findViewById(R.id.spinnerTime);
ArrayAdapter<CharSequence> Ad = ArrayAdapter.createFromResource(
this, R.array.timelist,
android.R.layout.simple_spinner_item);
Ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp1.setAdapter(Ad);
AlertDialog.Builder dia = new AlertDialog.Builder(
UCMapActivity.this);
dia.setTitle("查询空教室:");
dia.setView(textEntryView2);
dia.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = building.getText().toString().trim();
if (name.equals("")) {
toast("输入不能为空!");
} else {
FindRoomDao mts = new FindRoomDao(sqlite);
final View showRoomMessage = factory2.inflate(
R.layout.showroommessage, null);
final TextView showRoomText = (TextView) showRoomMessage
.findViewById(R.id.showRoomMessage);
showRoomText.setText("");
showRoomText.setText(mts.run(name, sp1
.getSelectedItem().toString()));
// new PopupWindow(showRoomMessage).showAtLocation(showRoomMessage, Gravity.BOTTOM, Gravity.LEFT, Gravity.RIGHT);
AlertDialog.Builder showRoomDia = new AlertDialog.Builder(
UCMapActivity.this) {
public AlertDialog show() {
//再次绑定View
setView(showRoomMessage);
return super.show();
}
};
showRoomDia.setTitle("查询空教室结果:");
showRoomDia.setView(showRoomText);
showRoomDia.setNegativeButton("确定",
new OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
arg0.dismiss();
}
});
showRoomDia.show();
}
}
});
dia.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dia.show();
而提示的大致意思是说为一个子视图指定了多个父视图。由此可以推断出,在第二次点击按钮弹出对话框时,子视图与第一次点击时的子视图是同一个对象,而父视图已经不再是同一个对象了。解决方法非常简单,只需要重写对话框的show()方法即可:
@Override
//重写show()方法
public AlertDialog show()
{
//再次绑定
View setView(GetTextEntryView());
return super.show();
}
- Android AlertDialog嵌套及二调用报错解决方法:The specified child already has a parent. You must call removeView()
- Android自定义Dialog二次调用报错解决方法:The specified child already has a parent. You must call removeView()
- 报错: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...
- 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
- The specified child already has a parent. You must call removeView().... 解决方法
- 嵌套Fragment的使用及遇到The specified child already has a parent. You must call removeView()问题的解决
- 嵌套Fragment的使用及遇到The specified child already has a parent. You must call removeView()问题的解决
- 嵌套Fragment的使用及遇到The specified child already has a parent. You must call removeView()问题的解决
- 嵌套Fragment的使用及遇到The specified child already has a parent. You must call removeView()问题的解决
- android viewp嵌套Fragment时遇到The specified child already has a parent. You must call removeView()问题的解决
- 总是报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() on the child's parent first.
- android The specified child already has a parent. You must call removeView() on the child's parent f
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's paren
- 搬砖问题、36个人搬36块砖,男搬4,女搬3,2个小孩招一砖。问男、女、小孩各若干?
- 找出数组中第一个只出现一次的字符
- c语言实现Java语言中contains函数
- Fence Loops
- 6.数组元素最大差(只能后面减前面)【dp】
- Android AlertDialog嵌套及二调用报错解决方法:The specified child already has a parent. You must call removeView()
- A计划
- 人生有四苦:我选择了承受痛苦
- 扩展欧几里得定理
- Oracle中CASE WHEN的用法实例(求班级男女生个数)
- [数据结构]程杰:散列表(哈希表)
- 数学专项counting:UVa 10237
- nyoj-891-找点
- C++中volatile的作用