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

PopupWindow

2015-11-10 18:24 183 查看
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;
}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  popwindow