码迷,mamicode.com
首页 > Windows程序 > 详细

关于PopupWindow的两个问题

时间:2014-10-16 00:52:31      阅读:433      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   blog   http   io   os   ar   java   

问题描述
第一个问题:PopupWindow里面的控件怎么监听。
第二个问题:怎么实现上下两个PopupWindow同时出现,同时消失,如多看阅读(见下图)
我的项目里是这样的:点击出现一个PopupWindow,但是里面的四个也需要点击监听,我应该怎么做?
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
我自己是这样写的

package com.freeplay.microdiary.activities;



import android.app.Activity;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;

import android.os.Bundle;

import android.util.Log;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.MotionEvent;

import android.view.View;

import android.view.WindowManager;

import android.widget.PopupWindow;

import android.widget.TextView;



import com.freeplay.microdiary.R;



import static com.freeplay.microdiary.R.id.edit_All;



public class EditActivity extends Activity {



    private TextView pic_TextView;

    private TextView location_TextView;

    private TextView weather_TextView;

    private PopupWindow mPopupWindow1;

    private PopupWindow mPopupWindow2;

    private PopupWindow mPopupWindow3;

    private TextView lastPic_TextView;

    private TextView takePhoto_TextView;

    private TextView cancel_TextView1;

    private TextView cancel_TextView2;

    private TextView cancel_TextView3;

    private TextView pic_Library_TextView;

    private Context mContext = null;





    @Override

    protected void onCreate(Bundle savedInstanceState) {

        System.out.println("启动EditActivity");

        super.onCreate(savedInstanceState);

        setContentView(R.layout.edit_activity);



        mContext=this;



        /*

        找到控件

         */

        pic_TextView = (TextView) findViewById(R.id.pic_TextView);

        location_TextView = (TextView) findViewById(R.id.location_TextView);

        weather_TextView = (TextView) findViewById(R.id.weather_TextView);



        /*

        PopupWindow相关

         */

        View popupView1 = getLayoutInflater().inflate(R.layout.pic_menu, null);

        pic_Library_TextView = (TextView) findViewById(R.id.pic_Library_TextView);

        pic_Library_TextView.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                System.out.println("点击了从图库里选择");

            }

        });



        mPopupWindow1 = new PopupWindow(popupView1, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);

        mPopupWindow1.setTouchable(true);

        mPopupWindow1.setOutsideTouchable(true);

        mPopupWindow1.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));

        mPopupWindow1.setAnimationStyle(R.style.anim_menu_bottombar);





        /*

        图片按钮监听器

         */

        pic_TextView.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                System.out.println("图片按钮点击");

                /*

                呈现三个选项:选取最后一张,拍照,打开图库选择

                 */

                mPopupWindow1.showAtLocation(findViewById(R.id.edit_All), Gravity.BOTTOM, 0, 0);





            }

        });















    }







}


但是这样点开就报错 解决方案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);

关于PopupWindow的两个问题

标签:des   android   style   blog   http   io   os   ar   java   

原文地址:http://www.cnblogs.com/shaochuyun57/p/4027418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!