Android: popup button dismiss on time?
<p>I have a popup button that is working fine. When i click on it it gets dismissed.
But i also want to add in a code for dismissing the popup after 5 secs if the user does not take any action on it? Is that possible?</p>

<p>The current code</p>

<pre><code>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();                          
                    //---
        }});
</code></pre>

<p>This is my updated code. What is wrong?</p>

<pre><code>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) {

            }
            };
            }});
</code></pre>
