Example usage for android.widget PopupWindow PopupWindow

List of usage examples for android.widget PopupWindow PopupWindow

Introduction

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

Prototype

public PopupWindow(View contentView, int width, int height) 

Source Link

Document

Create a new non focusable popup window which can display the contentView.

Usage

From source file:com.lines.activitys.OptionsActivity.java

/**
 * This method creates and shows a popup to the user, displaying a relevent
 * help message.//from   w w w .  j a v a 2s. co m
 * 
 * @param msg
 *            - decides which message we are displaying to the user
 * 
 */
private void showPopup(String msg) {
    // Create popup
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = layoutInflater.inflate(R.layout.help_popup_layout, null);
    final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
    TextView text = (TextView) popupView.findViewById(R.id.text);

    // Here we decide what help message to display to the user.
    if (msg.equals("cue")) {
        text.setText(R.string.cue_help);
    } else if (msg.equals("random")) {
        text.setText(R.string.random_help);
    } else if (msg.equals("own line")) {
        text.setText(R.string.own_line_help);
    } else if (msg.equals("stage")) {
        text.setText(R.string.stage_help);
    } else if (msg.equals("mode")) {
        text.setText(R.string.mode_help);
    }

    btnDismiss.setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {
            popupWindow.dismiss();
        }
    });

    popupWindow.showAsDropDown(mCueHelp, 50, -250);
}

From source file:com.givon.anhao.activity.AnhaoMainActivity.java

private void initPopuptWindow() {
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    View popupWindow = layoutInflater.inflate(R.layout.popup_window, null);

    mPopupWindow = new PopupWindow(popupWindow, AnhaoApplication.mWidth - 80, DensityUtil.dip2px(this, 200));
    mPopupWindow.setFocusable(true);//from   w w  w  .j  a va 2s .co  m
    // mPopupWindow.setWindowLayoutMode((mScreenWidth-mPopupWindowWidth)/2, mScreenHeight-mPopupWindowHeight);
    TextView popup_dismiss = (TextView) popupWindow.findViewById(R.id.tv_popup_dismiss);
    TextView popup_load = (TextView) popupWindow.findViewById(R.id.tv_load);
    TextView popup_camera = (TextView) popupWindow.findViewById(R.id.tv_photo);
    popup_dismiss.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getPopupWindowInstance();
        }
    });
    popup_load.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // 
            getPopupWindowInstance();
            loadPhotos();

        }
    });
    popup_camera.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // ?
            getPopupWindowInstance();
            selectPicFromCamera();
        }
    });
}

From source file:com.sft.blackcatapp.SearchCoachActivity.java

private void showPopupWindow(View parent) {
    if (popupWindow == null) {
        View view = View.inflate(mContext, R.layout.pop_window, null);

        TextView c1Car = (TextView) view.findViewById(R.id.pop_window_one);
        c1Car.setText(R.string.c1_automatic_gear_car);
        TextView c2Car = (TextView) view.findViewById(R.id.pop_window_two);
        c2Car.setText(R.string.c2_manual_gear_car);
        c1Car.setOnClickListener(this);
        c2Car.setOnClickListener(this);

        popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }/*from w  ww. j av  a 2  s.c o m*/
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    // Back???
    popupWindow.setBackgroundDrawable(new BitmapDrawable());

    popupWindow.showAsDropDown(parent);
}

From source file:com.lines.activitys.SettingsActivity.java

/**
 * This method creates and shows a popup to the user, displaying a relevent
 * help message.//from   w  ww .j  av  a  2s .  c o  m
 * 
 * @param msg
 *            - decides which message we are displaying to the user
 * 
 */
private void showPopup(String msg) {
    // Create popup
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = layoutInflater.inflate(R.layout.help_popup_layout, null);
    final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
    TextView text = (TextView) popupView.findViewById(R.id.text);

    // Here we decide what help message to display to the user.
    if (msg.equals("prompts")) {
        text.setText(R.string.prompt_help);
    } else {
        text.setText(R.string.auto_help);
    }

    btnDismiss.setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {
            popupWindow.dismiss();
        }
    });

    popupWindow.showAsDropDown(mPrompts, 50, -150);
}

From source file:com.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file//from  w  w  w. j  av a  2 s.  c om
 *
 * Editing launches a renaming process
 *
* @param longClickedFlow Flow represented by cardview longclicked
  * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
private boolean showLongClickPopUpMenu(final Flow longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("NO!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return true;
}

From source file:org.xingjitong.DialerFragment.java

@SuppressWarnings("deprecation")
@Override//from w ww  .  java  2  s.co  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    instance = this;
    handler = new Handler();
    MSG.getInstance().setFragment(this);
    if (view == null) {
        view = inflater.inflate(R.layout.dialer, container, false);

        list_ads = new ArrayList<View>();
        indicator = (CirclePageIndicator) view.findViewById(R.id.indicator);
        // ad view
        viewpager_dialer_ads = (AutoScrollViewPager) view.findViewById(R.id.viewpager_dialer_ads);
        final BitmapUtils utils = new BitmapUtils(getActivity(), "/sdcard/Download");
        utils.configDefaultLoadFailedImage(R.drawable.default_ad);
        // image ads config
        final ImageView view1 = new ImageView(getActivity());
        final ImageView view2 = new ImageView(getActivity());
        final ImageView view3 = new ImageView(getActivity());
        //         view1.setImageResource(R.drawable.ad1);
        //         view2.setImageResource(R.drawable.ad2);
        //         view3.setImageResource(R.drawable.ad3);
        //         final ImageView view4 = new ImageView(getActivity());
        //         final ImageView view5 = new ImageView(getActivity());

        view1.setScaleType(ScaleType.FIT_XY);
        view2.setScaleType(ScaleType.FIT_XY);
        view3.setScaleType(ScaleType.FIT_XY);
        //         view4.setScaleType(ScaleType.FIT_XY);
        //         view5.setScaleType(ScaleType.FIT_XY);

        android.view.ViewGroup.LayoutParams params = new LayoutParams(
                android.view.ViewGroup.LayoutParams.MATCH_PARENT, 200);

        view1.setLayoutParams(params);
        view2.setLayoutParams(params);
        view3.setLayoutParams(params);
        //         view4.setLayoutParams(params);
        //         view5.setLayoutParams(params);

        SharedPreferences prefs = getActivity().getSharedPreferences("ads", Context.MODE_PRIVATE);
        String adsString = prefs.getString("ads", null);
        if (adsString != null && adsString.length() > 0) {
            Map<String, Object> map = JsonToMapAds.getAdsList(adsString);
            if (map != null) {
                @SuppressWarnings("unchecked")
                List<Map<String, Object>> list_pau = (List<Map<String, Object>>) map.get("list");
                if (list_pau != null && list_pau.size() > 0) {
                    list2 = list_pau;
                    handler2.post(new Runnable() {

                        @Override
                        public void run() {
                            if (list2 != null && list2.size() >= 3) {
                                utils.display(view1, (String) list2.get(0).get("content"));
                                utils.display(view2, (String) list2.get(1).get("content"));
                                utils.display(view3, (String) list2.get(2).get("content"));
                                //                           view1.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(0).get("url")));
                                //                           view2.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(1).get("url")));
                                //                           view3.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(2).get("url")));
                            } else {
                                view1.setImageResource(R.drawable.default_ad);
                                view2.setImageResource(R.drawable.default_ad);
                                view3.setImageResource(R.drawable.default_ad);
                            }

                        }
                    });
                }
            }

        } else {
            view1.setImageResource(R.drawable.default_ad);
            view2.setImageResource(R.drawable.default_ad);
            view3.setImageResource(R.drawable.default_ad);
        }

        list_ads.add(view1);
        list_ads.add(view2);
        list_ads.add(view3);
        //         list_ads.add(view4);
        //         list_ads.add(view5);
        viewpager_dialer_ads.setAdapter(new MyAdPagerAdapter(list_ads));
        viewpager_dialer_ads.setOffscreenPageLimit(5);

        viewpager_dialer_ads.startAutoScroll();
        viewpager_dialer_ads.setInterval(5000);
        viewpager_dialer_ads.setSlideBorderMode(2);
        indicator.setViewPager(viewpager_dialer_ads);
        mAddress = (AddressText) view.findViewById(R.id.Adress);
        mAddress.setDialerFragment(this);
        mAddress.requestFocus();
        mAddress.setVisibility(View.VISIBLE);
        // yyppdial add
        dialhint = (TextView) view.findViewById(R.id.dialhint_tv);
        if (mAddress.length() == 0) {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 000");
            mAddress.setVisibility(View.GONE);
            dialhint.setVisibility(View.VISIBLE);
        } else {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 111");
            mAddress.requestFocus();
            mAddress.setVisibility(View.VISIBLE);
            dialhint.setVisibility(View.GONE);
        }
        // yyppdial end
        // yypp add
        Calendar c = Calendar.getInstance();
        // int month = c.get(Calendar.MONTH);
        // int date = c.get(Calendar.DATE);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (nongli == null)
            nongli = new Lunar(c);
        // nonglistr=nongli.toString();
        gonglistr = nongli.togongliString() + " ";
        nonglistr = "" + nongli.tonongliString() + " ";

        android.util.Log.v("yyppdebug", "yyppnotice dial 000");

        msg = MSG.getnewInstance(); // yyppnotice test

        android.util.Log.v("yyppdebug", "yyppnotice dialerfragment size:" + msg.msgs.size() + "");
        int drawid[] = {
                /*
                 * R.drawable.dial_notice0_img, R.drawable.dial_notice1_img,
                 * R.drawable.dial_notice2_img, R.drawable.dial_notice3_img,
                 * R.drawable.dial_notice4_img, R.drawable.dial_notice5_img,
                 * R.drawable.dial_notice6_img
                 */
        };
        // android.util.Log.v("yyppdebug", "yypp week="+week+"");
        /*
         * RelativeLayout rLayout = (RelativeLayout)
         * view.findViewById(R.id.dialer_notice_bg); Resources res =
         * getResources(); //resource handle Drawable drawable =
         * res.getDrawable(drawid[(week-1)%7]); //new Image that was added
         * to the res folder rLayout.setBackgroundDrawable(drawable);
         */

        // yypp end

        share = PreferenceManager.getDefaultSharedPreferences(getActivity());
        Bundle bundle = getArguments();
        if (bundle != null && mAddress != null) {
            int lBegin = mAddress.getSelectionStart();

            if (lBegin == -1) {
                lBegin = mAddress.length();
            }
            phone = bundle.getString("phone");
        }
        EraseButton erase = (EraseButton) view.findViewById(R.id.Erase);
        erase.setAddressWidget(mAddress);
        mCall = (CallButton) view.findViewById(R.id.Call);
        mCall.setAddressWidget(mAddress);
        if (LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
            if (isCallTransferOngoing) {
                mCall.setImageResource(R.drawable.transfer_call);
            } else {
                mCall.setImageResource(R.drawable.add_call);
            }
        } else {
            mCall.setImageResource(R.drawable.call);
        }

        AddressAware numpad = (AddressAware) view.findViewById(R.id.Dialer);
        if (numpad != null) {
            numpad.setAddressWidget(mAddress);
        }

        addContactListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                //add person to contacts 
                mylistener.onClick(mAddress.getText().toString());
                LinphoneActivity.instance().displayContactsForEdition(mAddress.getText().toString());
            }
        };
        cancelListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }
        };
        transferListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneCore lc = LinphoneManager.getLc();
                if (lc.getCurrentCall() == null) {
                    return;
                }
                lc.transferCall(lc.getCurrentCall(), mAddress.getText().toString());
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
                isCallTransferOngoing = false;
            }
        };

        mAddContact = (ImageView) view.findViewById(R.id.addContact);
        mAddContact
                .setEnabled(!(LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0));
        resetLayout(isCallTransferOngoing);

        if (getArguments() != null) {
            shouldEmptyAddressField = false;
            String number = getArguments().getString("SipUri");
            String displayName = getArguments().getString("DisplayName");
            String photo = getArguments().getString("PhotoUri");
            mAddress.setText(number);
            if (displayName != null) {
                mAddress.setDisplayedName(displayName);
            }
            if (photo != null) {
                mAddress.setPictureUri(Uri.parse(photo));
            }
        }
        // MATCH_PARENT WRAP_CONTENT //yyppdial.test
        /*
         * pop = new PopupWindow((getActivity().getLayoutInflater().inflate(
         * R.layout.dialer_list, null)),
         * ViewGroup.LayoutParams.WRAP_CONTENT,
         * ViewGroup.LayoutParams.WRAP_CONTENT);
         */

        pop = new PopupWindow((getActivity().getLayoutInflater().inflate(R.layout.dialer_list, null)),
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        if (pop != null) {
            pop.setFocusable(true);
            pop.setBackgroundDrawable(new BitmapDrawable());
            listView = (ListView) pop.getContentView().findViewById(R.id.dialer_pop_list);
        }
        if (listView != null) {
            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    mAddress.setDisplayedName(list.get(arg2).num);
                    mAddress.setText(list.get(arg2).num);
                    pop.dismiss();
                }
            });
        }

        // SpannableString str=new SpannableString("1234567890");
        // str.setSpan(new ForegroundColorSpan(Color.MAGENTA), 12, 15,
        // Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        showInfor = (ImageView) view.findViewById(R.id.dialer_infor_showimg1);
        if (showInfor != null) {
            showInfor.setOnClickListener(new OnClickListener() {
                @SuppressWarnings("unchecked")
                @Override
                public void onClick(View v) {
                    if (pop.isShowing()) {
                        pop.dismiss();
                    } else {
                        list = new CallInfor().getCallInfor((List<Contact>) ContactDB.Instance().getAllOb()[2],
                                CallsLogUtils.instance().getCallsLogs(), text);
                        if (list.size() == 0) {
                            return;
                        }
                        // yyyppset //yyppdal del
                        listView.setAdapter(new DialerListViewAdapter(getActivity(), list, text));
                        // pop.setWidth(view.getWidth());
                        pop.setWidth(view.getWidth() - 70);
                        pop.showAsDropDown(mAddress);

                        // yyppcall //yyppset add
                        /*
                         * ListAdapter madapter=new
                         * DialerListViewAdapter(getActivity(), list, text);
                         * //listView.setAdapter(new
                         * DialerListViewAdapter(getActivity(), list,
                         * text)); listView.setAdapter(madapter);
                         * 
                         * if (madapter.getCount()> 9) {
                         * pop.setHeight(view.getHeight()-60); } else {
                         * 
                         * pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                         * ; } pop.showAsDropDown(mAddress);
                         */
                        // yyppcall end

                    }
                }
            });
        }

        String tmpstr1 = "";
        if (UserConfig.getInstance().loginstatus == 0)
            tmpstr1 = "";
        else
            tmpstr1 = "";

        //

        /*
         * if (msc != null) { msc.setOnClickListener(new OnClickListener() {
         * 
         * @Override public void onClick(View v) { SettingHelp mes = new
         * SettingHelp(); Bundle bundle = new Bundle();
         * bundle.putInt("type", SettingHelp.NOTICE);
         * mes.setArguments(bundle);
         * mes.setStyle(DialogFragment.STYLE_NO_TITLE,
         * DialogFragment.STYLE_NORMAL);
         * mes.show(getActivity().getSupportFragmentManager(), "mes"); } });
         * }
         */
        // yyppdial end
    }
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);
    }

    // android.util.Log.i("xushuang", "<<<<2"+list2.toString());
    // views for ads

    return view;
}

From source file:mn.today.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file//ww w  .j  av  a2 s  .  c o  m
 *
 * Editing launches a renaming process
 *
 * @param longClickedFlow Flow represented by cardview longclicked
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private boolean showLongClickPopUpMenu(final ToDay longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return true;
}

From source file:com.imagine.BaseActivity.java

void makeErrorPopup(String text) {
    TextView view = new TextView(this);
    view.setText(text);/* w  ww  . j a  v  a2  s .  c o m*/
    final PopupWindow win = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    final View contentView = findViewById(android.R.id.content);
    contentView.post(new Runnable() {
        public void run() {
            win.showAtLocation(contentView, Gravity.CENTER, 0, 0);
        }
    });
}

From source file:com.example.leebeomwoo.viewbody_final.MainActivity.java

public void popupDisplay() {
    View popupView = getLayoutInflater().inflate(R.layout.menu, null);
    /**/*from   w  w  w.  jav a  2s  .c  o  m*/
     * LayoutParams WRAP_CONTENT  inflate? View? ? ??
     * PopupWinidow ?.
     *
     mPopupWindow = new PopupWindow(popupView,
     RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
     */
    mPopupWindow = new PopupWindow(popupView, 1000, RelativeLayout.LayoutParams.MATCH_PARENT);
    cancel_menuBtn = popupView.findViewById(R.id.cancel_menuBtn);
    account_menuBtn = popupView.findViewById(R.id.account_menuBtn);
    body_menuBtn = popupView.findViewById(R.id.body_menuBtn);
    follow_menuBtn = popupView.findViewById(R.id.follow_menuBtn);
    food_menuBtn = popupView.findViewById(R.id.food_menuBtn);
    qna_menuBtn = popupView.findViewById(R.id.qna_Btn);
    writer_menuBtn = popupView.findViewById(R.id.writer_menuBtn);
    menu_list = popupView.findViewById(R.id.menu_list);
    menu_Scroll = popupView.findViewById(R.id.menu_Scroll);
    btn_View = popupView.findViewById(R.id.btn_View);
    main = popupView.findViewById(R.id.menu_main);
    top = popupView.findViewById(R.id.menu_top);
    menuHomeBtn = popupView.findViewById(R.id.menuBtn_home);
    //licenseBtn = popupView.findViewById(R.id.license_Btn);
    license_source = popupView.findViewById(R.id.sourceTxt);
    license_Title = popupView.findViewById(R.id.titleTxt);
    checkedTextView = popupView.findViewById(R.id.menuchecked);

    cancel_menuBtn.setOnClickListener(this);
    account_menuBtn.setOnClickListener(this);
    body_menuBtn.setOnClickListener(this);
    follow_menuBtn.setOnClickListener(this);
    food_menuBtn.setOnClickListener(this);
    qna_menuBtn.setOnClickListener(this);
    writer_menuBtn.setOnClickListener(this);
    // licenseBtn.setOnClickListener(this);
    checkedTextView.setOnClickListener(this);
    SharedPreferences preferencesCompat = getSharedPreferences("a", MODE_PRIVATE);
    int tutorial = preferencesCompat.getInt("First", 0);
    if (tutorial == 0) {
        checkedTextView.setChecked(true);
    } else {
        checkedTextView.setChecked(false);
    }
    menu_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            final String item = (String) parent.getItemAtPosition(position);
            switch (item) {
            case "? ?":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "? ":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;
            case " ?":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(2);
                mPopupWindow.dismiss();
                break;
            case " ":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(3);
                mPopupWindow.dismiss();
                break;
            case "":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(4);
                mPopupWindow.dismiss();
                break;
            case " ?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;
            case "?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(2);
                mPopupWindow.dismiss();
                break;
            case " ?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(3);
                mPopupWindow.dismiss();
                break;
            case "?":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;
            case "?":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(2);
                mPopupWindow.dismiss();
                break;
            case "":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(3);
                mPopupWindow.dismiss();
                break;
            case "?":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(4);
                mPopupWindow.dismiss();
                break;
            case "?":
                writerTab_sub = new WriterTab_Sub();
                writerTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "?":
                writerTab_sub = new WriterTab_Sub();
                writerTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;

            }
        }

    });
    /**
     * @View anchor : anchor View    ? .
     * @ :  anchor View ?   View? ?
     * ??  ? .
     * xoff, yoff : anchor View  PopupWindow xoff x,
     * yoff y ? ??? ? ? .
     * @int xoff : -?(  ??), +?(  ??)
     * @int yoff : -?(  ??), +?(  ??)
     * achor View  ? ? .
     *  ,  ?? . ( ? ?)
     * mPopupWindow.showAsDropDown(btn_Popup, 50, 50);
     */
    mPopupWindow.setAnimationStyle(-1); // ? (-1:, 0:)

    /**
     * showAtLocation(parent, gravity, x, y)
     * @praent : PopupWindow ?? parent View 
     * View v = (View) findViewById(R.id.btn_click)?  parent ?
     * @gravity : parent View? Gravity ?  Popupwindow ? ?? .
     * @x : PopupWindow (-x, +x) ? , ??? ? ?
     * @y : PopupWindow (-y, +y) ? ?, ??? ? ?
     * mPopupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY, 0, 0);
     * */
    //mPopupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
    /**
     * update()   PopupWindow?  ?, x, y
     * anchor View   .
     * mPopupWindow.update(anchor, xoff, yoff, width, height)(width, height);
     */
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOutsideTouchable(true);
    Log.d("popup", "display");
    mPopupWindow.showAsDropDown(popupView, Gravity.END, 0, 0);
}

From source file:com.sft.blackcatapp.SearchCoachActivity.java

private void showOpenCityPopupWindow(View parent) {
    if (openCityPopupWindow == null) {
        LinearLayout popWindowLayout = (LinearLayout) View.inflate(mContext, R.layout.pop_window, null);
        popWindowLayout.removeAllViews();
        // LinearLayout popWindowLayout = new LinearLayout(mContext);
        popWindowLayout.setOrientation(LinearLayout.VERTICAL);
        ListView OpenCityListView = new ListView(mContext);
        OpenCityListView.setDividerHeight(0);
        OpenCityListView.setCacheColorHint(android.R.color.transparent);
        OpenCityListView.setOnItemClickListener(new OnItemClickListener() {

            @Override/*from   w w w  . ja va2  s. c  om*/
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                OpenCityVO selectCity = openCityList.get(position);
                System.out.println(selectCity.getName());
                cityname = selectCity.getName().replace("", "");
                licensetype = "";
                coachname = "";
                ordertype = "0";
                index = 1;
                obtainCaoch();
                openCityPopupWindow.dismiss();
                openCityPopupWindow = null;
            }
        });
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        popWindowLayout.addView(OpenCityListView, param);
        OpenCityAdapter openCityAdapter = new OpenCityAdapter(mContext, openCityList);
        OpenCityListView.setAdapter(openCityAdapter);

        openCityPopupWindow = new PopupWindow(popWindowLayout, 130, LayoutParams.WRAP_CONTENT);
    }
    openCityPopupWindow.setFocusable(true);
    openCityPopupWindow.setOutsideTouchable(true);
    // Back???
    openCityPopupWindow.setBackgroundDrawable(new BitmapDrawable());

    openCityPopupWindow.showAsDropDown(parent);
}