In my parent Activity i’ve a button, when i click on it shows PopUpWindow with 2 ImageButton.. When this PopUpWindow exists ‘m unable click my parent activity Button.. Here is my code, is there any problem in it..
public class PopUpExample extends Activity {
Button but;
LinearLayout mainLayout;
PopupWindow popUp;
boolean click = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout = (LinearLayout) findViewById(R.id.main_layout);
but = (Button) findViewById(R.id.main_btn);
but.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
View popView;
if(click){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
popUp = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100, 50, true);
popUp.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
popUp.update();
click = false;
popView = popUp.getContentView();
ImageButton call = (ImageButton) popView.findViewById(R.id.call_btn);
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopUpExample.this, "Calling...", Toast.LENGTH_SHORT).show();
}
});
ImageButton sms = (ImageButton) popView.findViewById(R.id.sms_btn);
sms.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopUpExample.this, "Sms...", Toast.LENGTH_SHORT).show();
}
});
}else{
popUp.dismiss();
click = true;
}
}
});
}
}
The popview when created takes away focus from the mainView so the user is not able to click the elements which are on the main view.
To click on the main view one need to dismiss popview first.
With respect to the above theory in your code You trying to dismiss popview by clicking on the button which is at main activity which is not possible.
Below code has the changes which you need to incorporate in your above code