This question is a development of the Java theme : to circumvent the need for an impossible change in the value of a local variable from the outside . From the answers to the question, I realized that the essence of the problem was not the one I had originally suggested, and it deserves a separate question.
I repeat the task. We have a FloatingActionButton; when clicked, a dialog box appears (or popupWindow , it doesn’t matter), and when clicked again, it disappears. Also, the window should disappear when clicked anywhere outside the window.
private void initFAB(){ fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { LayoutInflater layoutInflater = (LayoutInflater) getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE); View popupWindowContent = layoutInflater.inflate(R.layout.popup_window_content, null); final PopupWindow popupWindow = new PopupWindow(popupWindowContent, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setOutsideTouchable(true); if (fab.getTag().toString().equals("0")){ rotateFabForward(); View.OnClickListener onClickListener = new View.OnClickListener() { public void onClick(View view) { //... } }; // ... popupWindow.showAtLocation(fab, Gravity.END | Gravity.BOTTOM, 50, 400); fab.setTag("1"); // visible state } else{ rotateFabBackward(); popupWindow.dismiss(); fab.setTag("0"); // hidden state } } }); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { rotateFabBackward(); fab.setTag("0"); } }); } If you close the window just by touching outside the window, but without a button, everything will be fine. When you press the button to close the window, two events are Dismiss : Dismiss and Click . At the same time, they work, or sequentially, I don’t know, but anyway, OnDismissListener finishes execution earlier and we arrive at onClick with a zero tag and do not fall into else .
Anything can be done? Can there be an analogue of stopPropagation from JavaScript?
