I have 3 Image buttons and on press they each have a Popup window that opens up. The issue is when i click on button 1, there is a popup, if I DONT dismiss that popup but click on Button 2 instead, the pop-up for Button 1 and Button 2 appear.
How do i dismiss any open Pop-up’s when a new button is pressed?
Here is my 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.showAsDropDown(rredButton, 1, -1);
}});
And here is the other button (with a similar popup method)
final ImageButton ryellowButton=(ImageButton)findViewById(R.id.RyellowButton);
ryellowButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
createWrongPop(arg0);
}});
To do this you’ll need to save a reference to the PopupWindow in your class when the popup is shown, and clear it out when the popup is dismissed. Then, if you click the second button, you can check to see if the popup is available, and if it is, either call .dismiss() on it and create a new one, or modify it’s contents.