首页 > 代码库 > 安卓从popupwindow跳转到Activity页面

安卓从popupwindow跳转到Activity页面

在一个已出现的poupwindow中,点击页面上的某个按钮,页面将进行跳转到另一个Activity中。popupwindow代码如下:

 1 package com.cn.gordon.exhibition.walk.popup; 2  3 import com.cn.gordon.exhibition.walk.activity.ForumArrangementActivity; 4 import com.cn.gordon.exhibition.walk.activity.R; 5 import com.cn.gordon.exhibition.walk.activity.VisitPlanActivity; 6  7 import android.app.Activity; 8 import android.content.Context; 9 import android.content.Intent;10 import android.graphics.drawable.ColorDrawable;11 import android.view.LayoutInflater;12 import android.view.View;13 import android.view.View.OnClickListener;14 import android.widget.LinearLayout;15 import android.widget.PopupWindow;16 import android.widget.RelativeLayout.LayoutParams;17 18 public class ArrangementPopupWindow extends PopupWindow {19     private View contentView;20     public ArrangementPopupWindow(final Activity context){21         LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);22         contentView = inflater.inflate(R.layout.popupwindow_arrangement, null);23         //int h = context.getWindowManager().getDefaultDisplay().getHeight();24         int w = context.getWindowManager().getDefaultDisplay().getWidth();25         // 设置SelectPicPopupWindow的View26         this.setContentView(contentView);27         // 设置SelectPicPopupWindow弹出窗体的宽28         this.setWidth(w / 2 + 50);29         // 设置SelectPicPopupWindow弹出窗体的高30         this.setHeight(LayoutParams.WRAP_CONTENT);31         // 设置SelectPicPopupWindow弹出窗体可点击32         this.setFocusable(true);33         this.setOutsideTouchable(true);34         // 刷新状态35         this.update();36         // 实例化一个ColorDrawable颜色为半透明37         ColorDrawable dw = new ColorDrawable(0000000000);38         // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作39         this.setBackgroundDrawable(dw);40         // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);41         // 设置SelectPicPopupWindow弹出窗体动画效果42         //this.setAnimationStyle(R.style.AnimationPreview);43         LinearLayout layout_forum = (LinearLayout) contentView44                 .findViewById(R.id.layout_forum);45         LinearLayout layout_visitplan = (LinearLayout) contentView46                 .findViewById(R.id.layout_visitplanarrangement);47         48         layout_forum.setOnClickListener(new OnClickListener() {49             50             @Override51             public void onClick(View v) {52                 if (context.getClass().equals(VisitPlanActivity.class)) {53                     Intent in = new Intent(context,ForumArrangementActivity.class);54                     context.startActivity(in);55                     56                 }57                 ArrangementPopupWindow.this.dismiss(); 58             }59         });60         61 62         layout_visitplan.setOnClickListener(new OnClickListener() {63     64             @Override65             public void onClick(View v) {66                 if (context.getClass().equals(ForumArrangementActivity.class)) {67                     Intent in = new Intent(context,VisitPlanActivity.class);68                     context.startActivity(in);69                 }70                 71                 ArrangementPopupWindow.this.dismiss(); 72             }73         });74                 75     }76     77     public void showPopupWindow(View parent) {  78         if (!this.isShowing()) {  79             // 以下拉方式显示popupwindow  80             this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);  81         } else {  82             this.dismiss();  83         }  84     }  85 }

在popupwindow中需要用到上一个页面传递过来的context,通过context来调用startActivity实现页面的跳转。

安卓从popupwindow跳转到Activity页面