Android:在调用下一个窗口时解开一个弹出窗口



我有3个图像按钮,按下它们每个都有一个弹出窗口,可以打开。问题是当我单击按钮1时,会有一个弹出窗口,如果我不解开弹出窗口,但单击按钮2,则出现按钮1和按钮2的弹出窗口。按下新按钮时,如何解开任何开放式弹出式弹出式弹出式弹出式弹出式?

这是我的代码

final ImageButton rredButton=(ImageButton)findViewById(R.id.RredButton);
    rredButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            LayoutInflater layoutInflater
            = (LayoutInflater)getBaseContext()      
            .getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = layoutInflater.inflate(R.layout.popupright, null);
            final PopupWindow popupWindow = new PopupWindow(               
                    popupView,                
                    LayoutParams.WRAP_CONTENT,                       
                    LayoutParams.WRAP_CONTENT);     
            Button btnNxtScr = (Button)popupView.findViewById(R.id.nextscreen);             
            btnNxtScr.setOnClickListener(new Button.OnClickListener(){     
                @Override     
                public void onClick(View v) {      
                    Intent myintent1 = new Intent(colorActivity.this,colorBlueActivity.class);
                    startActivity(myintent1);
                }
            });
                    popupWindow.showAsDropDown(rredButton, 1, -1);
        }});

这是另一个按钮(具有类似的弹出方法)

final ImageButton ryellowButton=(ImageButton)findViewById(R.id.RyellowButton);
    ryellowButton.setOnClickListener(new View.OnClickListener() {
        @Override     
        public void onClick(View arg0) {          
            createWrongPop(arg0);      
            }});

要执行此操作,您需要在显示弹出窗口时保存对类中的弹出窗口的引用,并在解散弹出窗口时将其清除。然后,如果单击第二个按钮,则可以检查弹出窗口是否可用,如果是可用,则在其上拨打.dismiss()并创建一个新的,或修改其内容。

最新更新