做了一个ListView,想要实现点击任何一个item都可以弹出一个自定义的对话框。程序实现代码如下:// alert_selection.xml是自定义的对话框布局文件
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.alert_selection, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(view);
builder.setTitle("**");
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
builder.show();
}
});运行程序后第一次点击Item能够正常打开对话框,没有任何问题,但是点击其他位置关闭对话框之后。再次点击Item,程序就会崩溃,提示错误:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.请问该怎么解决?
- 1 回答
- 1 关注
- 2989 浏览
添加回答
举报
0/150
提交
取消