我有一个工作正常的弹出按钮。当我点击它时,它会被解雇。但是如果用户不对其采取任何操作,我还想添加一个代码以在 5 秒后关闭弹出窗口?那可能吗?
当前代码
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.showAtLocation(rredButton, Gravity.CENTER, 0, 0);
                    //---                          
                    popupWindow.setFocusable(true);             
                    popupWindow.update();                          
                    //---
        }});
这是我更新的代码。怎么了?
final ImageButton rredButton=(ImageButton)findViewById(R.id.RredButton);
    rredButton.setOnClickListener(new View.OnClickListener() {
        private CountDownTimer mPopUpDismissTimer; 
        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);     
            getPopUpDismissTimer(3000, 1000);
            mPopUpDismissTimer.start(); 
        }
            private void getPopUpDismissTimer(long millisInFuture, long countDownInterval) { 
            mPopUpDismissTimer = new CountDownTimer(millisInFuture, countDownInterval) {
            @Override
            public void onFinish() {
                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);
                    myintent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(myintent1);
                                };
        });
                popupWindow.showAtLocation(rredButton, Gravity.CENTER, 0, 0);
                //---                          
                popupWindow.setFocusable(true);             
                popupWindow.update();                          
                //---
            }
            @Override
            public void onTick(long millisUntilFinished) {
            }
            };
            }});