PopupWindow

popwindow弹框可以在activity上显示出一个对话框

public class DaoHan {
private String shouye;
private String personinfo;
private String myevent;
private String kaquan;
private String shezhi;
private String kefu;
private Context ct;
private PopupWindow popupWindow;
List data;
private ListView popItemList;
PopupWindowAdapter dadapter;
int width;
int height;
public DaoHan(Context ct) {
this.ct=ct;
initpopdata();
}
public void initpopdata(){

    shouye =  ct.getResources().getString(R.string.huidaoshouye);
    personinfo =  ct.getResources().getString(R.string.personinfo);
    myevent =  ct.getResources().getString(R.string.myevent);
    kaquan = ct.getResources().getString(R.string.kaquan);
    shezhi =  ct.getResources().getString(R.string.shezhi);
    kefu =  ct.getResources().getString(R.string.daohan_kefu);
    if(data!=null){
        data.clear();
    }
    data=new ArrayList<PopupWindowbean>();
    data.add(new PopupWindowbean(R.drawable.daohan_zhuye, shouye, R.drawable.arrows));
    data.add(new PopupWindowbean(R.drawable.daohan_ziliao, personinfo, R.drawable.arrows));
    data.add(new PopupWindowbean(R.drawable.nagi_ticket, kaquan, R.drawable.arrows));
    data.add(new PopupWindowbean(R.drawable.daohan_wode,myevent, R.drawable.arrows));
    data.add(new PopupWindowbean(R.drawable.daohan_kefu,kefu, R.drawable.arrows));
    data.add(new PopupWindowbean(R.drawable.nagi_set, shezhi, R.drawable.arrows));
}

public PopupWindow initPopupWindow() { /* 初始化PopupWindow */
    View popView = LayoutInflater.from(ct).inflate(R.layout.popupwindow, null,
            false); // 获取自定义的布局文件
    popItemList = (ListView) popView.findViewById(R.id.nagiItem);
    if(dadapter!=null){
        dadapter.notifyDataSetChanged();
    }else{
    dadapter = new PopupWindowAdapter(ct,data);
    popItemList.setAdapter(dadapter);
    popItemList.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            switch (position) {
            case 0:
                new CommonUtils(ct)
                .startActivity(Main1Activity.class);
                popupWindow.dismiss();
                break;
            case 1:
                new CommonUtils(ct)
                .startActivity(PersonActivity.class);
                popupWindow.dismiss();
                break;
            case 2:
                new CommonUtils(ct)
                .startActivity(MydiscountActivity.class);
                popupWindow.dismiss();
                break;
            case 3:
                new CommonUtils(ct)
                .startActivity(MyActivity.class);
                popupWindow.dismiss();
                break;
            case 4:
                new CommonUtils(ct)
                .startActivity(KeFuActivity.class);
                popupWindow.dismiss();
                break;
            case 5:
                new CommonUtils(ct)
                .startActivity(SafeoutActivity.class);
                popupWindow.dismiss();
                break;
            default:
                break;
            }               
        }
    });
    }
    WindowManager wm = ((Activity) ct).getWindowManager();
    width = wm.getDefaultDisplay().getWidth();
    height = wm.getDefaultDisplay().getHeight();
    popupWindow = new PopupWindow(popView, width * 2 / 3,ViewGroup.LayoutParams.WRAP_CONTENT,
            true); // 创建实例 宽度200 高度150
    popupWindow.setOutsideTouchable(true); // 设置点击外界关闭popwindow
    popupWindow.setTouchInterceptor(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return false;
        }
    });
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setFocusable(true);
    return popupWindow;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值