Example usage for android.widget ListPopupWindow ListPopupWindow

List of usage examples for android.widget ListPopupWindow ListPopupWindow

Introduction

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

Prototype

public ListPopupWindow(@NonNull Context context, @Nullable AttributeSet attrs) 

Source Link

Document

Create a new, empty popup window capable of displaying items from a ListAdapter.

Usage

From source file:com.silentcircle.contacts.editor.GroupMembershipView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/* w w w .  j  a  v a  2 s.c  om*/
public void onClick(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (mPopup != null && mPopup.isShowing()) {
            mPopup.dismiss();
            return;
        }
    } else {
        groupCheckDialogDismiss();
    }

    mAdapter = new GroupMembershipAdapter<GroupSelectionItem>(getContext(),
            R.layout.group_membership_list_item);

    mGroupMetaData.moveToPosition(-1);
    while (mGroupMetaData.moveToNext()) {
        long groupId = mGroupMetaData.getLong(GroupMetaDataLoader.GROUP_ID);
        if (groupId != mFavoritesGroupId && (groupId != mDefaultGroupId || mDefaultGroupVisible)) {
            String title = mGroupMetaData.getString(GroupMetaDataLoader.TITLE);
            boolean checked = hasMembership(groupId);
            mAdapter.add(new GroupSelectionItem(groupId, title, checked));
        }
    }

    mAdapter.add(new GroupSelectionItem(CREATE_NEW_GROUP_GROUP_ID,
            getContext().getString(R.string.create_group_item_label), false));

    ListView listView;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mPopup = new ListPopupWindow(getContext(), null);
        mPopup.setAnchorView(mGroupList);
        mPopup.setAdapter(mAdapter);
        mPopup.setModal(true);
        mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
        mPopup.show();
        listView = mPopup.getListView();
    } else {
        GroupCheckPopup.modeList = listView = new ListView(parent.getActivity());
        listView.setAdapter(mAdapter);
    }
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setOverScrollMode(OVER_SCROLL_ALWAYS);
    int count = mAdapter.getCount();
    for (int i = 0; i < count; i++) {
        listView.setItemChecked(i, mAdapter.getItem(i).isChecked());
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        groupCheckDialog(mAdapter);
    }
    listView.setOnItemClickListener(this);
}