如何在Android中的Array Adapter类中关闭弹出窗口

时间:2016-01-09 04:35:47

标签: android

我创建弹出窗口并在ListView项目点击事件上打开弹出窗口。弹出窗口中有两个按钮,一个是btnCamera,另一个是btnDismiss。问题是当我捕获图像并返回到当时弹出窗口中的listview没有自动取消。我试图在Activity中取消弹出窗口onResume()方法。

@Override
    protected void onResume() {
        super.onResume();
 if(adapter.popupWindow_Camera != null)
        {
            adapter.popupWindow_Camera.dismiss();
            adapter.popupWindow_Camera = null;
        }

    }

这是ListView项目上的弹出窗口,单击。

    holder.imgBtn_Camera.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v)
                    {
                        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        View popupView = layoutInflater.inflate(R.layout.camera_popup, (ViewGroup) ((Activity) context).findViewById(R.id.popup_element));
                        popupWindow_Camera = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        popupWindow_Camera.setWidth(720);
                        popupWindow_Camera.setHeight(350);
                        popupWindow_Camera.setFocusable(true);
                        popupWindow_Camera.showAtLocation(popupView, Gravity.BOTTOM, 0, 87);
                        popupWindow_Camera.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

                        Button btnCamera = (Button) popupView.findViewById(R.id.button_Camera);
                        Button btnGallery = (Button) popupView.findViewById(R.id.button_Gallery);
                        Button btnDismiss = (Button) popupView.findViewById(R.id.btnCancelCamera);

                        btnCamera.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v)
 {
                              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "classnkk_images";
                            File myPath = new File(extr, picformat);
                            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(myPath));
                            ((Activity) context).startActivityForResult(cameraIntent, CAMERA_REQUEST);
                            Log.e("Camera", " Open");
                            popupWindow_Camera.dismiss();  
                            }
                        });

                        btnDismiss.setOnClickListener(new Button.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                popupWindow_Camera.dismiss();
                            }
                        });

                        popupWindow_Camera.showAsDropDown(holder.imgBtn_Camera, 50, -30);
                    }
                });

有人可以帮我解决这个问题。谢谢。

1 个答案:

答案 0 :(得分:0)

//当您打算使用startActivityOnResult()时,与完成相机操作相比,onActivityResult()方法将被调用...所以你应该在onResultActivity()中尝试这个“popupWindow_Camera.dismiss();”。