Example usage for android.widget ListPopupWindow setContentWidth

List of usage examples for android.widget ListPopupWindow setContentWidth

Introduction

In this page you can find the example usage for android.widget ListPopupWindow setContentWidth.

Prototype

public void setContentWidth(int width) 

Source Link

Document

Sets the width of the popup window by the size of its content.

Usage

From source file:com.ruesga.rview.fragments.DownloadDialogFragment.java

private void showDownloadTypeChooser(View anchor) {
    final ListPopupWindow popupWindow = new ListPopupWindow(getContext());
    SimpleDropDownAdapter adapter = new SimpleDropDownAdapter(getContext(), mDownloadTypes,
            mModel.downloadType);/*from  w w  w  .j a v  a2s.co  m*/
    popupWindow.setAnchorView(anchor);
    popupWindow.setAdapter(adapter);
    popupWindow.setContentWidth(adapter.measureContentWidth());
    popupWindow.setOnItemClickListener((parent, view, position, id) -> {
        popupWindow.dismiss();

        // Update the view
        mModel.downloadType = mDownloadTypes.get(position);
        mBinding.downloadCommands.from(mDownloadCommands.get(mModel.downloadType)).update();
        mBinding.setModel(mModel);
        mBinding.executePendingBindings();
    });
    popupWindow.setModal(true);
    popupWindow.show();
}

From source file:android.support.v7ox.widget.ActivityChooserView.java

/**
 * Shows the popup no matter if it was already showing.
 *
 * @param maxActivityCount The max number of activities to display.
 *//*w w  w  .j a  v a 2  s .  c  o  m*/
private void showPopupUnchecked(int maxActivityCount) {
    if (mAdapter.getDataModel() == null) {
        throw new IllegalStateException("No data model. Did you call #setDataModel?");
    }

    getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);

    final boolean defaultActivityButtonShown = mDefaultActivityButton.getVisibility() == VISIBLE;

    final int activityCount = mAdapter.getActivityCount();
    final int maxActivityCountOffset = defaultActivityButtonShown ? 1 : 0;
    if (maxActivityCount != ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED
            && activityCount > maxActivityCount + maxActivityCountOffset) {
        mAdapter.setShowFooterView(true);
        mAdapter.setMaxActivityCount(maxActivityCount - 1);
    } else {
        mAdapter.setShowFooterView(false);
        mAdapter.setMaxActivityCount(maxActivityCount);
    }

    ListPopupWindow popupWindow = getListPopupWindow();
    if (!popupWindow.isShowing()) {
        if (mIsSelectingDefaultActivity || !defaultActivityButtonShown) {
            mAdapter.setShowDefaultActivity(true, defaultActivityButtonShown);
        } else {
            mAdapter.setShowDefaultActivity(false, false);
        }
        final int contentWidth = Math.min(mAdapter.measureContentWidth(), mListPopupMaxWidth);
        popupWindow.setContentWidth(contentWidth);
        popupWindow.show();
        if (mProvider != null) {
            mProvider.subUiVisibilityChanged(true);
        }
        popupWindow.getListView().setContentDescription(
                getContext().getString(R.string.abc_activitychooserview_choose_application));
    }
}