コード例 #1
0
 /**
  * 只要是年月发生变化,就要去检查日是否也联动发生变化(比如有些年份二月28天,有些年份是29天)
  *
  * @param mYearWheelView2
  * @param mMonthWheelView2
  * @param mDayWheelView2 void
  */
 private void updateDays(WheelView year, WheelView month, WheelView day) {
   // 选择的年月对应的那个月总共有多少天
   Calendar calendar = Calendar.getInstance();
   calendar.set(Calendar.YEAR, year.getCurrentItem());
   calendar.set(Calendar.MONTH, month.getCurrentItem());
   mMaxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
   mDayAdapter =
       new WheelNumericAdapter(this, 1, mMaxDay, getString(R.string.putao_personal_data_day));
   mDayWheelView.setViewAdapter(mDayAdapter);
 }
コード例 #2
0
 /** 当省份滑动改变时,相应的改变城市 void */
 private void updateCities() {
   // 获取当前选中省份的索引
   int currentIndex = mProvinceWheelView.getCurrentItem();
   ProvinceItem currentProvince = mProvinceItems.get(currentIndex);
   LinkedList<String> cityList = currentProvince.cityList;
   // 清空城市列表
   mCitiesList.clear();
   if (cityList != null && cityList.size() > 0) {
     mCitiesList.addAll(cityList);
   } else {
     mCitiesList.add("---");
   }
   mCityAdapter.setData(mCitiesList);
   mCityWheelView.setCurrentItem(0);
 }
コード例 #3
0
 /** 弹出生日选择框 void */
 private void showBirthdayDialog() {
   if (mBirthdayDialog == null) {
     mBirthdayDialog = CommonDialogFactory.getDialog(this, R.style.Theme_Ptui_Dialog_Wheel);
     mBirthdayDialog.setTitle(getString(R.string.putao_personal_data_birthday));
     mBirthdayDialog.setNegativeButton(
         R.string.putao_cancel,
         new OnClickListener() {
           @Override
           public void onClick(View view) {
             mBirthdayDialog.dismiss();
           }
         });
     mBirthdayDialog.setPositiveButton(
         R.string.putao_confirm,
         new OnClickListener() {
           @Override
           public void onClick(View view) {
             mBirthdayDialog.dismiss();
             mChangeFlag = true;
             int year = mYearWheelView.getCurrentItem() + mCurrentYear - 100;
             int month = mMonthWheelView.getCurrentItem() + 1;
             int day = mDayWheelView.getCurrentItem() + 1;
             StringBuilder sb = new StringBuilder();
             sb.append(year).append("-").append(month).append("-").append(day);
             mBirthdaySTR = sb.toString();
             mBirthdayTextView.setText(mBirthdaySTR);
           }
         });
     LinearLayout wheelContainer = (LinearLayout) mBirthdayDialog.getContainerLayout();
     // 年,年月的滚动控件不用设置滚动事件监听
     Calendar calendar = Calendar.getInstance();
     mCurrentYear = calendar.get(Calendar.YEAR);
     mYearWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_left);
     mYearWheelView.setVisibleItems(3);
     mYearAdapter =
         new WheelNumericAdapter(
             this, mCurrentYear - 100, mCurrentYear, getString(R.string.putao_personal_data_year));
     mYearWheelView.setViewAdapter(mYearAdapter);
     // 月
     mMonthWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_center);
     mMonthWheelView.setVisibleItems(3);
     mMonthAdapter =
         new WheelNumericAdapter(this, 1, 12, getString(R.string.putao_personal_data_month));
     mMonthWheelView.setViewAdapter(mMonthAdapter);
     // 日
     mDayWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_right);
     mDayWheelView.setVisibleItems(3);
     OnWheelChangedListener listener =
         new OnWheelChangedListener() {
           @Override
           public void onChanged(WheelView wheel, int oldValue, int newValue) {
             // 只要是年月发生变化,就要去检查日是否也联动发生变化
             updateDays(mYearWheelView, mMonthWheelView, mDayWheelView);
           }
         };
     mYearWheelView.addChangingListener(listener);
     mMonthWheelView.addChangingListener(listener);
     updateDays(mYearWheelView, mMonthWheelView, mDayWheelView);
   }
   // mBirthdaySTR是否为空
   if (!TextUtils.isEmpty(mBirthdaySTR)) {
     try {
       String[] date = mBirthdaySTR.split("-");
       String year = "";
       String month = "";
       String day = "";
       if (date.length > 0) {
         year = date[0];
       }
       // 将year转为为year index
       if (!TextUtils.isEmpty(year)) {
         int yearIndex = Integer.parseInt(year) - (mCurrentYear - 100);
         mYearWheelView.setCurrentItem(yearIndex);
       }
       if (date.length > 1) {
         month = date[1];
       }
       // 将month转化为month index
       if (!TextUtils.isEmpty(month)) {
         int monthIndex = Integer.parseInt(month) - 1;
         mMonthWheelView.setCurrentItem(monthIndex);
       }
       if (date.length > 2) {
         day = date[2];
       }
       // 将day转化为day index
       if (!TextUtils.isEmpty(day)) {
         int dayIndex = Integer.parseInt(day) - 1;
         mDayWheelView.setCurrentItem(dayIndex);
       }
     } catch (Exception e) {
       LogUtil.w("YellowpagePersonalInfoActivity", "catch Exception throw by choosePicture", e);
     }
   } else {
     mYearWheelView.setCurrentItem(73);
   }
   mBirthdayDialog.show();
 }
コード例 #4
0
  private void showWheelCityDialog() {
    dismissLoadingDialog();
    if (mCityDialog == null) {
      mCityDialog = CommonDialogFactory.getDialog(this, R.style.Theme_Ptui_Dialog_Wheel);
      mCityDialog.setTitle(getString(R.string.putao_personal_data_area));
      mCityDialog.setNegativeButton(
          getString(R.string.putao_cancel),
          new OnClickListener() {
            @Override
            public void onClick(View view) {
              mCityDialog.dismiss();
            }
          });
      mCityDialog.setPositiveButton(
          getString(R.string.putao_confirm),
          new OnClickListener() {

            @Override
            public void onClick(View view) {
              mCityDialog.dismiss();
              mChangeFlag = true;
              // 提取滑轮中的省份和城市
              ProvinceItem provinceItem = mProvinceItems.get(0);
              String city = "";
              int provinceIndex = mProvinceWheelView.getCurrentItem();
              if (provinceIndex >= 0 && provinceIndex < mProvinceItems.size()) {
                provinceItem = mProvinceItems.get(provinceIndex);
                mCitiesList.clear();
                mCitiesList.addAll(provinceItem.cityList);
                int cityIndex = mCityWheelView.getCurrentItem();
                if (cityIndex >= 0 && cityIndex < mCitiesList.size()) {
                  city = mCitiesList.get(cityIndex);
                  if ("---".equals(city)) {
                    city = "";
                  }
                }
                StringBuilder sb = new StringBuilder();
                sb.append(provinceItem.provinceName).append("  ").append(city);
                mCitySTR = sb.toString();
                mCityTextView.setText(mCitySTR);
              }
            }
          });

      LinearLayout wheelContainer = (LinearLayout) mCityDialog.getContainerLayout();
      // 只有省市两级联动,把中间的wheelview去掉
      wheelContainer.findViewById(R.id.wheel_center).setVisibility(View.GONE);
      mProvinceWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_left);
      mProvinceWheelView.setVisibleItems(3);
      mProvinceAdapter = new WheelTextAdapter(this, mProvincesList);
      mProvinceWheelView.setViewAdapter(mProvinceAdapter);
      mProvinceWheelView.addChangingListener(this);

      mCityWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_right);
      mCityWheelView.setVisibleItems(3);
      mCityAdapter = new WheelTextAdapter(this, mCitiesList);
      mCityWheelView.setViewAdapter(mCityAdapter);
      mCityWheelView.addChangingListener(this);
    }

    // 显示已设定的城市,或显示默认第一个
    if (!TextUtils.isEmpty(mCitySTR)) {
      // 省份和城市之间是以两个空格来分开的
      String[] area = mCitySTR.split("  ");
      String province = "";
      String city = "";
      if (area.length > 0) {
        province = area[0];
      }
      if (area.length > 1) {
        city = area[1];
      }
      // 遍历省份列表
      if (!mProvinceItems.isEmpty() && !TextUtils.isEmpty(province)) {
        for (int i = 0; i < mProvinceItems.size(); i++) {
          if (mProvinceItems.get(i).provinceName.equals(province)) {
            mProvinceWheelView.setCurrentItem(i);
            mCitiesList.clear();
            mCitiesList.addAll(mProvinceItems.get(i).cityList);
            break;
          }
        }
      }
      // 遍历城市列表
      if (!mCitiesList.isEmpty() && !TextUtils.isEmpty(city)) {
        for (int j = 0; j < mCitiesList.size(); j++) {
          if (mCitiesList.get(j).equals(city)) {
            mCityWheelView.setCurrentItem(j);
            break;
          }
        }
      }
    } else {
      mProvinceWheelView.setCurrentItem(0);
      mProvinceAdapter.setData(mProvincesList);
      mCityWheelView.setCurrentItem(0);
      mCityAdapter.setData(mCitiesList);
    }

    mCityDialog.show();
  }