我有像下面这样的弹出窗口类.
public class Popup extends PopupWindow {
Context context;
EditText et_bankname, et_banknumber;
String bank_name, account_number;
public Popup(Context ctx) {
super(ctx);
context = ctx;
setContentView(LayoutInflater.from(context).inflate(R.layout.bank_details, null));
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
View popupView = getContentView();
setFocusable(true);
Button btn_close = (Button) popupView.findViewById(R.id.popupClose);
Button btn_submit = (Button) popupView.findViewById(R.id.popupSave);
et_bankname = (EditText) popupView.findViewById(R.id.bank_name);
et_banknumber = (EditText) popupView.findViewById(R.id.bankacc_no);
btn_submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
bank_name = et_bankname.getText().toString();
account_number = et_banknumber.getText().toString();
if (!bank_name.equals("") && !account_number.equals("")) {
Toast t1 = Toast.makeText(context,bank_name + " "+account_number , Toast.LENGTH_SHORT);
t1.setGravity(Gravity.TOP, 0, 100);
t1.show();
dismiss();
} else {
Toast t1 = Toast.makeText(context,
"Please provide valid details", Toast.LENGTH_SHORT);
t1.setGravity(Gravity.TOP, 0, 100);
t1.show();
}
}
});
}
public void show(View v) {
showAtLocation(v, Gravity.CENTER, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
我将在我的活动中访问此弹出窗口
Popup popup = new Popup(getBaseContext());
popup.show(arg1);
Run Code Online (Sandbox Code Playgroud)
这非常有效.但我想知道这个弹出窗口何时被解雇.为此目的,我现在使用Thread如下概念.
if (isPopupShowing) {
Thread thread = new Thread() {
@Override
public void run() {
while (isPopupShowing) {
if (!popup.isShowing()) {
isPopupShowing = false;
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
loadDSP(type);
}
});
}
}
}
};
thread.start();
}
Run Code Online (Sandbox Code Playgroud)
但是这个线程将继续运行,直到弹出窗口被解除.所以我觉得用其他方式替换这个解决方案会更好.
我想要的是?当popup被解雇时,就像"popup is closed"这样的活动非常亲密.
为什么我这样用?我将在三个活动中使用此弹出窗口.这就是我为弹出窗口创建一个单独的类的原因.
任何帮助都会受到高度关注.
谢谢.
PopupWindow已经有了自己的dismiss监听器,只需按如下方式使用它
Popup popup = new Popup(getBaseContext());
popup.show(arg1);
Run Code Online (Sandbox Code Playgroud)
改为
Popup popup = new Popup(getBaseContext());
popup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
// Do your action
}
});
popup.show(arg1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3264 次 |
| 最近记录: |