Popwindow 选择日期

 /**
     * 月份popwindow需要变量
     */
    private static int days = 0; // 月的天数
    private static int year = 2017;
    private static int month = 0;
    private static String[] dates;
    private Map<String, String> dateMap;
    private List<String> dateList;
    private PopupWindow popupWindow;
    private ListView dateListView;
    private String tradeStartDate;
    private String tradeEndDate;
    private String startRecord = "0";
    private String tradeTotal;


 private void inidData() {
        int thisYear = CalendarUtil.getYear(0);
        year = thisYear;
        dates = new String[12];
        int j = 0;
        for (int i = 0; i > -12; i--) {
            int thisMonth = CalendarUtil.getMonth(0);
            month = CalendarUtil.getMonth(i);
            if (12 != thisMonth && 12 == month) {
                year = CalendarUtil.getYear(-1);
            }
            String startDate = "";
            if (10 > month) {
                startDate = year + "-" + "0" + month;
            } else {
                startDate = year + "-" + month;
            }
            String endDate = year + "-" + month;
            dates[j] = startDate;
            j = j + 1;
            int days = CalendarUtil.getPreviousMonthEndDay(i);
            endDate = startDate + "-" + days;
            dateMap.put(startDate, endDate);
            dateList.add(startDate);
        }
        
    }




/**
     * 初始化popWindow
     */
    private void initPopWindow() {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View popView = inflater.inflate(R.layout.account_information_pop, null);
        popupWindow = new PopupWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(false);
        popupWindow.setOutsideTouchable(false);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {


            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
        // popupWindow.setAnimationStyle(R.style.PopupAnimation);


        dateListView = (ListView) popView.findViewById(R.id.date_list_id);
        ArrayAdapter<String> list = new ArrayAdapter<String>(this,
                R.layout.list_item_spinner, dateList);
        dateListView.setAdapter(list);
        dateListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                                    int position, long arg3) {
                // TODO Auto-generated method stub
                Log.e(TAG, "dateListView: onItemClick. position == " + position);
                tradeTotal = "0.00";
                dismissPop();
                String date = (String) dateListView.getItemAtPosition(position);
                Log.e(TAG, "dateListView: onItemClick. date 1 == " + date);
                date = dateList.get(position);


                // String dateString = arg0.getSelectedItem().toString();
                // Log.e(TAG,
                // "dateListView: onItemClick dateString :"+dateString);
                mMonthDaysText.setText(date);
                queryUserBonusPutForwardHandler(date);
                tradeStartDate = date + "-01";
                tradeEndDate = (String) dateMap.get(date).toString();
                startRecord = "0";
            }
        });


    }


    /**
     * 显示popWindow
     */
    private void showPop() {
        if (isFinishing()) {
            return;
        }
        if (popupWindow == null) {
            initPopWindow();
        }
        if (!popupWindow.isShowing()) {
            popupWindow.showAsDropDown(mLlSelectDate,
                    DensityUtil.dip2px(this, 20), 0);
            // 设置背景颜色变暗
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.alpha = 0.4f;
            getWindow().setAttributes(lp);
        }
        popupWindow.update();
    }


    private boolean dismissPop() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
            return true;
        }
        return false;
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (dismissPop()) {
            return true;
        }
        return super.dispatchTouchEvent(ev);
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值