Java Code Examples for android.support.v7.widget.ListPopupWindow#show()
The following examples show how to use
android.support.v7.widget.ListPopupWindow#show() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiImageSelectorFragment.java From ImageSelector with Apache License 2.0 | 6 votes |
void showDirectories() { if (imageDirectories.size() <= 1) { return; } final ListPopupWindow popupWindow = new ListPopupWindow(this.getActivity()); popupWindow.setBackgroundDrawable(new ColorDrawable(-1)); popupWindow.setAdapter(new DirectoryAdapter(this.getActivity(), this.imageDirectories)); popupWindow.setWidth(-1); int itemHeight = this.getActivity().getResources().getDimensionPixelOffset(R.dimen.size_60); popupWindow.setHeight(this.imageDirectories.size() >= 5 ? itemHeight * 5 : itemHeight * this.imageDirectories.size() + getActivity().getResources().getDimensionPixelOffset(R.dimen.size_10)); popupWindow.setAnchorView(this.btnBack); popupWindow.setModal(true); popupWindow.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { txtTitle.setText(imageDirectories.get(position).getName()); mAdapter.changeData(imageDirectories.get(position).getImages()); currentDirectory = position; popupWindow.dismiss(); } }); popupWindow.show(); popupWindow.getListView().setDividerHeight(getActivity().getResources().getDimensionPixelOffset(R.dimen.size_10)); popupWindow.getListView().setDivider(new ColorDrawable(getResources().getColor(android.R.color.transparent))); popupWindow.setSelection(this.currentDirectory); }
Example 2
Source File: MenuPopupHelper.java From floatingsearchview with Apache License 2.0 | 5 votes |
public boolean tryShow() { mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes); mPopup.setOnDismissListener(this); mPopup.setOnItemClickListener(this); mPopup.setAdapter(mAdapter); mPopup.setModal(true); View anchor = mAnchorView; if (anchor != null) { final boolean addGlobalListener = mTreeObserver == null; mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest if (addGlobalListener) mTreeObserver.addOnGlobalLayoutListener(this); mPopup.setAnchorView(anchor); mPopup.setDropDownGravity(mDropDownGravity); } else { return false; } if (!mHasContentWidth) { mContentWidth = measureContentWidth(); mHasContentWidth = true; } mPopup.setContentWidth(mContentWidth); mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); int vertOffset = -mAnchorView.getHeight() + Util.dpToPx(4); int horizontalOffset = -mContentWidth + mAnchorView.getWidth(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { vertOffset = -mAnchorView.getHeight() - Util.dpToPx(4); horizontalOffset = -mContentWidth+mAnchorView.getWidth()-Util.dpToPx(8); } mPopup.setVerticalOffset(vertOffset); mPopup.setHorizontalOffset(horizontalOffset); mPopup.show(); mPopup.getListView().setOnKeyListener(this); return true; }
Example 3
Source File: SampleActivity.java From Falcon with Apache License 2.0 | 5 votes |
@OnClick(R.id.show_popup) public void showPopup() { ListPopupWindow listPopupWindow = new ListPopupWindow(this, null); String[] data = {"Item 1", "Item 2", "Item 3"}; ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data); listPopupWindow.setAdapter(adapter); listPopupWindow.setAnchorView(findViewById(R.id.show_popup)); listPopupWindow.show(); }