Android PopupWindow You must call removeView() on the child's parent first.
来源:互联网 发布:mysql安装教程5.7.17 编辑:程序博客网 时间:2024/05/21 21:43
package com.mcdull.picker.ui;import android.app.Activity;import android.content.Intent;import android.graphics.drawable.ColorDrawable;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.widget.AdapterView;import android.widget.ListView;import android.widget.PopupWindow;import com.hanshuang.mcdull.picker.R;import com.hanshuang.mcdull.picker.adapter.PhotoAlbumLVAdapter;import com.hanshuang.mcdull.picker.model.PhotoModel;import java.util.ArrayList;/** *选择相册 */public class PhotoAlbumPopwindow extends PopupWindow implements AdapterView.OnItemClickListener{ private LayoutInflater mLayoutInflater; private Activity mContext; private ListView mListView; private ArrayList<PhotoModel> list; public PhotoAlbumPopwindow(Activity context) { super(); mLayoutInflater = LayoutInflater.from(context); this.mContext = context; initView(); } private void initView() { View view = mLayoutInflater.inflate(R.layout.popwindow_layout,null); mListView = (ListView) view.findViewById(R.id.popwindow_layout_list); int h = mContext.getWindowManager().getDefaultDisplay().getHeight(); int w = mContext.getWindowManager().getDefaultDisplay().getWidth(); // 设置SelectPicPopupWindow的View this.setContentView(mListView); // 设置SelectPicPopupWindow弹出窗体的宽 this.setWidth(w); // 设置SelectPicPopupWindow弹出窗体的高 this.setHeight(h); // 设置SelectPicPopupWindow弹出窗体可点击 this.setFocusable(true); this.setOutsideTouchable(true); // 刷新状态 this.update(); // 实例化一个ColorDrawable颜色为半透明 ColorDrawable dw = new ColorDrawable(0xb0000000); // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作 this.setBackgroundDrawable(dw); mListView.setOnItemClickListener(this); } /** * 显示popupWindow * * @param parent */ public void showPopupWindow(View parent, ArrayList<PhotoModel> list) { if(!list.isEmpty()) this.list=list; if (!this.isShowing()) { // 以下拉方式显示popupwindow PhotoAlbumLVAdapter adapter = new PhotoAlbumLVAdapter(mContext, list); mListView.setAdapter(adapter); this.showAsDropDown(parent, Gravity.BOTTOM, 0); } else { this.dismiss(); } } @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Intent intent = new Intent(mContext, PhotoWallActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); //第一行为“最近照片” if (position == 0) { intent.putExtra("code", 200); } else { intent.putExtra("code", 100); intent.putExtra("folderPath", list.get(position).getPathName()); } mContext.startActivity(intent); this.dismiss(); }}
运行起来报错:<span style="color:#ff0000;">You must call removeView() on the child's parent first</span>.
后来发现问题原来在给PopupWindow 设置View上
因为ListView属于View 所以不能直接set子布局
this.setContentView(mListView);改
this.setContentView(view);
解决,代码有的时候写的太马虎,以后要多注意.
0 0
- Android PopupWindow You must call removeView() on the child's parent first.
- You must call removeView() on the child's parent first
- You must call removeView() on the child's parent first
- Android关于You must call removeView() on the child's parent first的解决
- Android 开发 Tip 4 -- You must call removeView() on the child's parent first
- You must call removeView() on the child's parent first错误的解决方法
- 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.
- 二、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
- 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.
- 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
- 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.
- 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.
- ffmpeg解码流程
- 学习笔记_Git之分支创建策略
- 3. PSR-3 --- 日志接口
- 设计模式必须通过面向对象来实现吗?
- phpStorm mac下的快捷键
- Android PopupWindow You must call removeView() on the child's parent first.
- android操作系统上的web浏览器开发
- JPA之@Access注解
- Struts2中ValueStack的学习
- 50 家硅谷 IT 公司技术博客
- 2015年工作中遇到的问题141-150
- 单链表
- mysql 显示行号,以及分组排序
- Vert.x 3学习笔记---15( Web篇 )