0
        int height = buildDropDown();
 
        int widthSpec = 0;
        int heightSpec = 0;
 
        if (mPopup.isShowing()) {
            if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) {
                // The call to PopupWindow's update method below can accept -1 for any 
                // value you do not want to update. 
                widthSpec = -1;
            } else if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
                widthSpec = getAnchorView().getWidth();
            } else { 
                widthSpec = mDropDownWidth;
            } 
 
            if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
                // The call to PopupWindow's update method below can accept -1 for any 
                // value you do not want to update. 
                heightSpec = height;
                
                    mPopup.setWindowLayoutMode(
                            mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ?
                                    ViewGroup.LayoutParams.MATCH_PARENT : 0,
                            ViewGroup.LayoutParams.MATCH_PARENT);
            
            } else if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
                heightSpec = height;
            } else { 
                heightSpec = mDropDownHeight;
            } 
 
            mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible);
 
            mPopup.update(getAnchorView(), mDropDownHorizontalOffset,
                    mDropDownVerticalOffset, widthSpec, heightSpec);
        } else { 
            if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) {
                widthSpec = ViewGroup.LayoutParams.MATCH_PARENT;
            } else { 
                if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
                    mPopup.setWidth(getAnchorView().getWidth());
                } else { 
                    mPopup.setWidth(mDropDownWidth);
                } 
            } 
 
            if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
                heightSpec = ViewGroup.LayoutParams.MATCH_PARENT;
            } else { 
                if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
                    mPopup.setHeight(height);
                } else { 
                    mPopup.setHeight(mDropDownHeight);
                } 
            } 
 
            mPopup.setWindowLayoutMode(widthSpec, heightSpec);
            //mPopup.setClipToScreenEnabled(true); 
             
            // use outside touchable to dismiss drop down when touching outside of it, so 
            // only set this if the dropdown is not always visible 
            mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible);
           
            mPopup.showAsDropDown(getAnchorView(),
                    mDropDownHorizontalOffset, mDropDownVerticalOffset);
            mDropDownList.setSelection(ListView.INVALID_POSITION);
             
            if (!mModal || mDropDownList.isInTouchMode()) {
                clearListSelection(); 
            } 
             
        } 
    } 
 
    /** 
     * Dismiss the popup window. 
     */ 
    public void dismiss() { 
        mPopup.dismiss();
        mPopup.setContentView(null);
        mDropDownList = null;
    } 
 
    /** 
     * Set a listener to receive a callback when the popup is dismissed. 
     * 
     * @param listener Listener that will be notified when the popup is dismissed. 
     */ 
    public void setOnDismissListener(PopupWindow.OnDismissListener listener) {
        mPopup.setOnDismissListener(listener);
    } 
 
    /** 
     * Control how the popup operates with an input method: one of 
     * {@link #INPUT_METHOD_FROM_FOCUSABLE}, {@link #INPUT_METHOD_NEEDED}, 
     * or {@link #INPUT_METHOD_NOT_NEEDED}. 
     *  
     * <p>If the popup is showing, calling this method will take effect only 
     * the next time the popup is shown or through a manual call to the {@link #show()} 
     * method.</p> 
     *  
     * @see #getInputMethodMode() 
     * @see #show() 
     */ 
    public void setInputMethodMode(int mode) {
        mPopup.setInputMethodMode(mode);
    } 
 
    /** 
     * Return the current value in {@link #setInputMethodMode(int)}. 
     *  
     * @see #setInputMethodMode(int) 
     */ 
    public int getInputMethodMode() { 
        return mPopup.getInputMethodMode();
    } 
 
    /** 
     * Set the selected position of the list. 
     * Only valid when {@link #isShowing()} == {@code true}. 
     *  
     * @param position List position to set as selected. 
     */ 
    public void setSelection(int position) {
        DropDownListView list = mDropDownList;
        if (isShowing() && list != null) {
            list.mListSelectionHidden = false;
            list.setSelection(position);
            if (list.getChoiceMode() != ListView.CHOICE_MODE_NONE) {
                list.setItemChecked(position, true);
            } 
        } 
    } 
 
    /** 
     * Clear any current list selection. 
     * Only valid when {@link #isShowing()} == {@code true}. 
     */ 
    public void clearListSelection() { 
        final DropDownListView list = mDropDownList;
        if (list != null) {
            // WARNING: Please read the comment where mListSelectionHidden is declared 
            list.mListSelectionHidden = true;
            //list.hideSelector(); 
            list.requestLayout();
        } 
    } 
 
    /** 
     * @return {@code true} if the popup is currently showing, {@code false} otherwise. 
     */ 
    public boolean isShowing() { 
        return mPopup.isShowing();
    } 
 
    /** 
     * Perform an item click operation on the specified list adapter position. 
     *  
     * @param position Adapter position for performing the click 
     * @return true if the click action could be performed, false if not. 
     *         (e.g. if the popup was not showing, this method would return false.) 
     */ 
    public boolean performItemClick(int position) {
        if (isShowing()) { 
            if (mItemClickListener != null) {
                final DropDownListView list = mDropDownList;
                final View child = list.getChildAt(position - list.getFirstVisiblePosition());
                final ListAdapter adapter = list.getAdapter();
                mItemClickListener.onItemClick(list, child, position, adapter.getItemId(position));
            } 
            return true; 
        } 
        return false; 
    } 
 
    /** 
     * @return The currently selected item or null if the popup is not showing. 
     */ 
    public Object getSelectedItem() {
        if (!isShowing()) { 
            return null; 
        } 
        return mDropDownList.getSelectedItem();
    } 
 
    /** 
     * @return The position of the currently selected item or {@link ListView#INVALID_POSITION} 
     * if {@link #isShowing()} == {@code false}. 
     *  
     * @see ListView#getSelectedItemPosition() 
     */ 
    public int getSelectedItemPosition() { 
        if (!isShowing()) { 
            return ListView.INVALID_POSITION;
        } 
        return mDropDownList.getSelectedItemPosition();
    } 
 
    /** 
     * @return The ID of the currently selected item or {@link ListView#INVALID_ROW_ID} 
     * if {@link #isShowing()} == {@code false}. 
     *  
     * @see ListView#getSelectedItemId() 
     */ 
    public long getSelectedItemId() { 
        if (!isShowing()) { 
            return ListView.INVALID_ROW_ID;
        } 
        return mDropDownList.getSelectedItemId();
    } 
 
    /** 
     * @return The View for the currently selected item or null if 
     * {@link #isShowing()} == {@code false}. 
     *  
     * @see ListView#getSelectedView() 
     */ 
    public View getSelectedView() {
        if (!isShowing()) { 
            return null; 
        } 
        return mDropDownList.getSelectedView();
    } 
 
    /** 
     * @return The {@link ListView} displayed within the popup window. 
     * Only valid when {@link #isShowing()} == {@code true}. 
     */ 
    public ListView getListView() {
        return mDropDownList;
    } 
 
    /** 
     * The maximum number of list items that can be visible and still have 
     * the list expand when touched. 
     * 
     * @param max Max number of items that can be visible and still allow the list to expand. 
     */ 
    void setListItemExpandMax(int max) {
        mListItemExpandMaximum = max;
    } 
 
    /** 
     * <p>Builds the popup window's content and returns the height the popup 
     * should have. Returns -1 when the content already exists.</p> 
     * 
     * @return the content's height or -1 if content already exists 
     */ 
    private int buildDropDown() { 
        ViewGroup dropDownView;
        int otherHeights = 0;
 
        if (mDropDownList == null) {
            Context context = mContext;
 
            /** 
             * This Runnable exists for the sole purpose of checking if the view layout has got 
             * completed and if so call showDropDown to display the drop down. This is used to show 
             * the drop down as soon as possible after user opens up the search dialog, without 
             * waiting for the normal UI pipeline to do it's job which is slower than this method. 
             */ 
            mShowDropDownRunnable = new Runnable() {
                public void run() { 
                    // View layout should be all done before displaying the drop down. 
                    View view = getAnchorView();
                    if (view != null && view.getWindowToken() != null) {
                        show(); 
                    } 
                } 
            }; 
 
            mDropDownList = new DropDownListView(context, !mModal);
            if (mDropDownListHighlight != null) {
                mDropDownList.setSelector(mDropDownListHighlight);
            } 
            mDropDownList.setAdapter(mAdapter);
            mDropDownList.setOnItemClickListener(mItemClickListener);
            mDropDownList.setFocusable(true);
            mDropDownList.setFocusableInTouchMode(true);
            mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view,
                        int position, long id) {
 
                    if (position != -1) {
                        DropDownListView dropDownList = mDropDownList;
 
                        if (dropDownList != null) {
                            dropDownList.mListSelectionHidden = false;
                        } 
                    } 
                } 
 
                public void onNothingSelected(AdapterView<?> parent) {
                } 
            }); 
           
 
            if (mItemSelectedListener != null) {
                mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
            } 
 
            dropDownView = mDropDownList;
            mPopup.setContentView(dropDownView);
        } else { 
            dropDownView = (ViewGroup) mPopup.getContentView();
        } 
 
        // getMaxAvailableHeight() subtracts the padding, so we put it back 
        // to get the available height for the whole window 
        int padding = 0;
        Drawable background = mPopup.getBackground();
        if (background != null) {
            background.getPadding(mTempRect);
            padding = mTempRect.top + mTempRect.bottom;
 
            // If we don't have an explicit vertical offset, determine one from the window 
            // background so that content will line up. 
            if (!mDropDownVerticalOffsetSet) {
                mDropDownVerticalOffset = -mTempRect.top;
            } 
        } 
 
        final int maxHeight = mPopup.getMaxAvailableHeight(
                getAnchorView(), mDropDownVerticalOffset);
 
        if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
            return maxHeight + padding;
        }