Example usage for android.widget ListPopupWindow setAdapter

List of usage examples for android.widget ListPopupWindow setAdapter

Introduction

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

Prototype

public void setAdapter(@Nullable ListAdapter adapter) 

Source Link

Document

Sets the adapter that provides the data and the views to represent the data in this popup window.

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  a 2 s  .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:com.android.settings.users.EditUserPhotoController.java

private void showUpdatePhotoPopup() {
    final boolean canTakePhoto = canTakePhoto();
    final boolean canChoosePhoto = canChoosePhoto();

    if (!canTakePhoto && !canChoosePhoto) {
        return;/*from  ww  w  . j a va2 s . co m*/
    }

    final Context context = mImageView.getContext();
    final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>();

    if (canTakePhoto) {
        final String title = context.getString(R.string.user_image_take_photo);
        final Runnable action = new Runnable() {
            @Override
            public void run() {
                takePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }

    if (canChoosePhoto) {
        final String title = context.getString(R.string.user_image_choose_photo);
        final Runnable action = new Runnable() {
            @Override
            public void run() {
                choosePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }

    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);

    listPopupWindow.setAnchorView(mImageView);
    listPopupWindow.setModal(true);
    listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items));

    final int width = Math.max(mImageView.getWidth(),
            context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width));
    listPopupWindow.setWidth(width);
    listPopupWindow.setDropDownGravity(Gravity.START);

    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position);
            item.doAction();
        }
    });

    listPopupWindow.show();
}