Code example for ListPopupWindow

Methods: dismiss, isShowing, show

0
	 * Dismiss the popup window. 
	 */ 
	@Override 
	public void dismiss() { 
		if (isPopupWindowShowing()) { 
			mWindow.dismiss();
		} 
	} 
 
	@Override 
	public Menu getMenu() {
		return mMenu;
	} 
 
	public MenuInflater getMenuInflater() {
		return new MenuInflater(mContext);
	} 
 
	@Override 
	public void inflate(int menuRes) {
		new MenuInflater(mContext).inflate(menuRes, mMenu);
	} 
 
	@Override 
	public void onDismiss() { 
		if (!mDidAction && mDismissListener != null) {
			mDismissListener.onDismiss(this);
		} 
	} 
 
	@Override 
	public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
		mDidAction = true;
		dismiss(); 
		final MenuItem item = mAdapter.getItem(position);
		if (item.hasSubMenu()) {
			showMenu(item.getSubMenu());
		} else { 
			if (mItemClickListener != null) {
				mItemClickListener.onMenuItemClick(item);
			} 
		} 
	} 
 
	@Override 
	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
			mWindow.dismiss();
 
			return true; 
		} 
 
		return false; 
	} 
 
	@Override 
	public void setMenu(Menu menu) {
		mMenu = menu;
	} 
 
	/** 
	 * Set listener for window dismissed. This listener will only be fired if 
	 * the quickaction dialog is dismissed by clicking outside the dialog or 
	 * clicking on sticky item. 
	 */ 
	@Override 
	public void setOnDismissListener(PopupMenu.OnDismissListener listener) {
		mWindow.setOnDismissListener(listener != null ? this : null);
 
		mDismissListener = listener;
	} 
 
	/** 
	 * Set listener for action item clicked. 
	 *  
	 * @param listener Listener 
	 */ 
	@Override 
	public void setOnMenuItemClickListener(OnMenuItemClickListener listener) {
		mItemClickListener = listener;
	} 
 
	@Override 
	public void show() { 
		if (isPopupWindowShowing()) { 
			dismiss(); 
		} 
		showMenu(getMenu()); 
	} 
 
	private boolean isPopupWindowShowing() { 
		if (mWindow == null) return false;
		return mWindow.isShowing();
	} 
 
	private void showMenu(Menu menu) {
		mAdapter.setMenu(menu);
		mWindow.show();
	} 
 
}