Android - Prevent button click outside of PopupWindow -


i've spent while trying work, looked similar solutions online, none seem work. need popupwindow dismissed on click of generate button, not clicking outside window. encountered issue before?

private void loadramspopup() {     mainlayout.getforeground().setalpha(150);     layoutinflater layoutinflater = (layoutinflater) getbasecontext().getsystemservice(layout_inflater_service);      final view ramsview = layoutinflater.inflate(r.layout.popup_rams, null);     final popupwindow popuprams = new popupwindow(             ramsview,             viewgroup.layoutparams.wrap_content,             viewgroup.layoutparams.wrap_content     );      if (build.version.sdk_int >= 21) {         popuprams.setelevation(5.0f);     }      findviewbyid(r.id.mainlayout).post(new runnable() {         @override         public void run() {             popuprams.showatlocation(findviewbyid(r.id.mainlayout), gravity.center, 0, 0);             popuprams.setoutsidetouchable(false);             popuprams.setfocusable(true);             popuprams.update();              button btngenerate = (button) ramsview.findviewbyid(r.id.btngenerate);             btngenerate.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view view) {                     intent intent = new intent(getapplicationcontext(), createramsactivity.class);                     startactivity(intent);                     popuprams.dismiss();                     mainlayout.getforeground().setalpha(0);                 }             });         }     }); } 

setting popuprams.setfocusable(false). removes unnecessary touch required make popup window disappear. please replace

popuprams.setfocusable(true); 

with

popuprams.setfocusable(false); 

also try add

popuprams.setoutsidetouchable(false); 

hope out.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -