Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListPopupWindow's method isShowing() does not work

I've decided to create my own custom spinner by extending a TextView and composing a ListPopupWindow. I want to emulate the following functionality of the original Spinner: when the spinner is clicked the drop down list is shown, the second time the spinner is clicked the drop down list is dismissed. But I'm having some trouble, the ListPopupWindow.isShowing() seems to always return false (I've debugged it):

public class CustomSpinner extends TextView {
    ...
    private ListPopupWindow dropDownPopup;
    ...
    public CustomSpinner(Context context, AttributeSet attrs) {
        super(context, attrs);
        ...
        dropDownPopup = new ListPopupWindow(context, attrs);
        dropDownPopup.setAnchorView(this);
        dropDownPopup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        dropDownPopup.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                dropDownPopup.dismiss();
                ...
            }
        });     

        this.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {                
                if (dropDownPopup.isShowing()) {
                    dropDownPopup.dismiss();
                } else {
                    dropDownPopup.show();
                }
            }
        });
    }

So, each time I click on the spinner the drop down list is shown. It is dismissed when I click on one of the items in the list. The problem seems to be that dropDownPopup.isShowing() always returns false.

like image 509
Daniel Rusev Avatar asked Apr 22 '14 08:04

Daniel Rusev


1 Answers

By setting dropDownPopup.setModal(true), everything works.

like image 147
Daniel Rusev Avatar answered Oct 26 '22 23:10

Daniel Rusev