Reputation: 25
I am trying to create a popup window when a certain menu item is pressed. I think I have most of the code, however I am not sure what to do for showAtLocation(...) or showAsDropDown(...).
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
...
case R.id.about:
displayPopupWindow();
return true;
...
}
}
public void displayPopupWindow() {
PopupWindow popup = new PopupWindow(this);
View layout = getLayoutInflater().inflate(R.layout.popup, null);
popup.setContentView(layout);
popup.setOutsideTouchable(true);
popup.setFocusable(true);
popup.showAtLocation(??, Gravity.CENTER, 0, 0);
}
What should i put for the view for the menu or should I do this another way? I hope that makes sense and thanks for the help!
Upvotes: 1
Views: 5316
Reputation: 10869
i know its been 4months, maybe you've passed it, but im your solution, and i just signed up here yesterday, so yh.. Here's the solution to your problem, copy and paste..
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
...
case R.id.about:
displayPopupWindow();
return true;
...
}
}
public void displayPopupWindow() {
PopupWindow popup = new PopupWindow(this);
View layout = getLayoutInflater().inflate(R.layout.popup, null);
popup.setContentView(layout);
popup.setOutsideTouchable(true);
popup.setFocusable(true);
popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
}
So basically what you do is you use the view you inflated which is "layout" in your case.. Hope it helps, Let me know...
Upvotes: 8