1、初始化弹出层数据
private final Dialog createDialog(int layoutId) {
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题
dialog.setContentView(layoutId);
Window mwindow = dialog.getWindow();
WindowManager.LayoutParams lp = mwindow.getAttributes();
mwindow.setBackgroundDrawableResource(android.R.color.transparent);
lp.gravity = Gravity.BOTTOM;
mwindow.setAttributes(lp);
mwindow.setWindowAnimations(R.style.dialogWindowAnim);
// dialog.setCanceledOnTouchOutside(false); // 设置点击外部不可消失
return dialog;
}
2.处理点击确定和取消操作
/** 收藏商家和取消商家按钮点击事件 **/
private OnClickListener collection_bussiness_Listener = new OnClickListener() {
@Override
public void onClick(View v) {
if (member != null ) {
final Dialog dialogCollection = createDialog(R.layout.dialog_bussiness_collection);
TextView isCollection = (TextView) dialogCollection.findViewById(R.id.dialog_bussiness_collection_tv); // 是否收藏
Button confrimBtn = (Button) dialogCollection.findViewById(R.id.dialog_confirm); //确定
Button cancelBtn = (Button) dialogCollection.findViewById(R.id.dialog_cancel); // 取消
if (!StringUtil.isNull(isCollect) && "true".equals(isCollect) && collectionId != null) {
isCollection.setText("是否确认取消收藏商家?");
} else if (!StringUtil.isNull(isCollect) && "false".equals(isCollect) && societyBussiness != null && societyBussiness.getId() != null){
isCollection.setText("是否确认收藏商家?");
}
confrimBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialogCollection.dismiss();
if (loadStateView != null) {
loadStateView.startLoad();//启动转圈
}
Thread collThread = new Thread(new DealCollectionRunnable());
collThread.start();
}
});
// 取消
cancelBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialogCollection.dismiss();
}
});
dialogCollection.show();
}else {
//去登录
Intent intent = new Intent(context,LoginActivity.class);
startActivity(intent);
}
}
};