PopupWindow怎么用?

一个Activity里有两个Fragment,fragment里面放的是一个Listview,
我点一个条目中的button时,在屏幕的下方弹出来一个popupWindow,要弹出来popupWindow,要设置
pop.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);
这个时候的parentView要传谁?
我现在传的是fragment所在的activity的布局,这个是报错的,代码:

new popupWindow和给popupWindow填充布局的代码:
public static PopupWindow createPopupWindow(Context context, final popupWindowCallback callback)
    {
        final PopupWindow mPopupwindow = new PopupWindow(context);
//         View view = View.inflate(context, R.layout.add_goods_popup,null);
        View view = LayoutInflater.from(context).inflate(R.layout.add_goods_popup, null);;
               
        root_popup = (RelativeLayout) view.findViewById(R.id.root_popup);
        mPopupwindow.setWidth(LayoutParams.MATCH_PARENT);
        mPopupwindow.setHeight(LayoutParams.WRAP_CONTENT);
        mPopupwindow.setBackgroundDrawable(new BitmapDrawable());
        mPopupwindow.setFocusable(true);
        mPopupwindow.setOutsideTouchable(true);
        mPopupwindow.setContentView(view);
        
        ImageButton ib_pop_close = (ImageButton) view.findViewById(R.id.ib_pop_close);
        // 整个线性布局
        root_popup.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mPopupwindow.dismiss();
//                 root_popup.clearAnimation();
            }
        });
        return mPopupwindow;
        
    }

使用popupWindow时的代码:
pop =Utils.createPopupWindow(context.getApplicationContext(), new popupWindowCallback() {

       @Override
       public void cancelClickListener() {

       }      
      pop.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);
}

因为是在listview的item中点击button时弹出来popupWindow的,所以代码也就放在adapter类里面了,只要一执行下面代码就
崩溃了。
pop.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值