您的位置:首页 > 运维架构

关于PopupWindow的两个问题

2014-10-15 21:38 190 查看
问题描述

第一个问题:PopupWindow里面的控件怎么监听。

第二个问题:怎么实现上下两个PopupWindow同时出现,同时消失,如多看阅读(见下图)

我的项目里是这样的:点击出现一个PopupWindow,但是里面的四个也需要点击监听,我应该怎么做?







我自己是这样写的


但是这样点开就报错

解决方案1

private class PopupWindows extends PopupWindow {

@SuppressWarnings("deprecation")

@TargetApi(Build.VERSION_CODES.CUPCAKE)

@SuppressLint("NewApi")

public PopupWindows(Context mContext, View parent) {

super(mContext);

View view = View.inflate(mContext,

R.layout.zhgl_userinfo_avatarupdate, null);

view.startAnimation(AnimationUtils.loadAnimation(mContext,

R.anim.fade_ins));

LinearLayout ll_popup = (LinearLayout) view

.findViewById(R.id.ll_popup);

ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,

R.anim.push_bottom_in_2));

setWidth(LayoutParams.FILL_PARENT);

setHeight(LayoutParams.FILL_PARENT);

setBackgroundDrawable(new BitmapDrawable());

setFocusable(true);

setOutsideTouchable(true);

setContentView(view);

showAtLocation(parent, Gravity.BOTTOM, 0, 0);

update();

Button bt1 = (Button) view

.findViewById(R.id.item_popupwindows_camera);

Button bt2 = (Button) view

.findViewById(R.id.item_popupwindows_Photo);

Button bt3 = (Button) view

.findViewById(R.id.item_popupwindows_cancel);

bt1.setOnClickListener(new OnClickListener() {

// 通过相机获得图片

public void onClick(View v) {

Intent intentFromCapture = new Intent(

MediaStore.ACTION_IMAGE_CAPTURE);

intentFromCapture.putExtra(

MediaStore.EXTRA_OUTPUT,

Uri.fromFile(new File(Environment

.getExternalStorageDirectory(), "head2.png")));

// intentFromCapture.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,

// 1);

startActivityForResult(intentFromCapture,

CAMERA_REQUEST_CODE);

dismiss();

}

});

bt2.setOnClickListener(new OnClickListener() {

// 从本地选取图片

public void onClick(View v) {

Intent intentFromGallery = new Intent();

intentFromGallery.setType("image/*"); // 设置文件类型

intentFromGallery.setAction(Intent.ACTION_GET_CONTENT);

startActivityForResult(intentFromGallery,

IMAGE_REQUEST_CODE);

dismiss();

}

});

bt3.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

dismiss();

}

});

}

}


然后在activity里 new PopupWindows(UserInfoActivity.this, aiv);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: