基于上一篇写的UserBirthdayDialog
来源:互联网 发布:中国新歌声网络直播权 编辑:程序博客网 时间:2024/04/19 20:20
从下部弹上来的UserBirthdayDialog
至于push_bottom_in.xml和push_bottom_out.xml见http://gundumw100.iteye.com/blog/2163571
import java.util.Calendar;import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.util.DisplayMetrics;import android.view.Gravity;import android.view.View;import android.view.Window;import android.view.WindowManager;import com.widget.wheel.NumericWheelAdapter;import com.widget.wheel.OnWheelScrollListener;import com.widget.wheel.WheelView;import com.yirui.youbao.app.R;/** * * @author pythoner * */public class UserBirthdayDialog extends Dialog{ private Context context; private WheelView year, month, day; private String date; public UserBirthdayDialog(Context context, String date) { this(context, R.style.Theme_Dialog_From_Bottom, date); // TODO Auto-generated constructor stub } public UserBirthdayDialog(Context context, int theme, String date) { super(context, theme); // TODO Auto-generated constructor stub this.context = context; this.date = date; init(); } private void init() { this.setCanceledOnTouchOutside(true); this.setCancelable(true); } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.dialog_user_birthday); initViews(); initValues(); } private void initViews() { findViewById(R.id.btn_left).setOnClickListener(clickListener); findViewById(R.id.btn_right).setOnClickListener(clickListener); String icurYear, icurMonth, icurDay; Calendar c = Calendar.getInstance(); int curYear = c.get(Calendar.YEAR); if (date == null || date.length() < 10) {// 格式不正确 int curMonth = c.get(Calendar.MONTH); int curDay = c.get(Calendar.DAY_OF_MONTH); icurYear = String.valueOf(curYear); icurMonth = String.valueOf(curMonth + 1); icurDay = String.valueOf(curDay); } else {// 年月日 icurYear = date.substring(0, 4); icurMonth = date.substring(5, 7); icurDay = date.substring(8, 10); } year = (WheelView) findViewById(R.id.year); year.setAdapter(new NumericWheelAdapter(curYear - 100, curYear)); // year.setLabel("年"); year.setCurrentItem(Integer.parseInt(icurYear) - Integer.parseInt(year.getAdapter().getItem(0))); month = (WheelView) findViewById(R.id.month); month.setAdapter(new NumericWheelAdapter(1, 12));// "%02d" // month.setLabel("月"); month.setCyclic(true); month.setCurrentItem(Integer.parseInt(icurMonth) - 1); int daysOfMounth = getDaysOfMounth(); day = (WheelView) findViewById(R.id.day); day.setAdapter(new NumericWheelAdapter(1, daysOfMounth)); // day.setLabel("日"); day.setCyclic(true); day.setCurrentItem(Integer.parseInt(icurDay) - 1); OnWheelScrollListener scrollListener = new OnWheelScrollListener() { public void onScrollingStarted(WheelView wheel) { } public void onScrollingFinished(WheelView wheel) { int daysOfMounth = getDaysOfMounth(); day.setAdapter(new NumericWheelAdapter(1, daysOfMounth)); } }; year.addScrollingListener(scrollListener); month.addScrollingListener(scrollListener); // day.addScrollingListener(scrollListener); } private void initValues() { // 不能写在init()中 Window window = getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); DisplayMetrics dm = context.getResources().getDisplayMetrics(); lp.width = dm.widthPixels; lp.gravity = Gravity.BOTTOM; window.setAttributes(lp); } private int getDaysOfMounth() { int mMonth = Integer.parseInt(month.getAdapter().getItem(month.getCurrentItem())); switch (mMonth) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: int mYear = Integer.parseInt(year.getAdapter().getItem(year.getCurrentItem())); if (mYear % 4 == 0 && mYear % 100 != 0 || mYear % 400 == 0) { return 29; } else { return 28; } } return -1; } View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_left: dismiss(); break; case R.id.btn_right: String mYear = year.getAdapter().getItem(year.getCurrentItem()); String mMonth = month.getAdapter().getItem(month.getCurrentItem()); String mDay = day.getAdapter().getItem(day.getCurrentItem()); if (mDay == null || mDay.length() == 0) { mDay = "1"; } if (Integer.parseInt(mMonth) < 10) { mMonth = "0" + mMonth; } if (Integer.parseInt(mDay) < 10) { mDay = "0" + mDay; } if (onOKClickListener != null) { onOKClickListener.onOKClick(v, mYear, mMonth, mDay); } dismiss(); break; default: break; } } }; private OnOKClickListener onOKClickListener; public interface OnOKClickListener { public void onOKClick(View v, String year, String month, String day); } public void setOnOKClickListener(OnOKClickListener onOKClickListener) { this.onOKClickListener = onOKClickListener; }}
<style name="Theme_Dialog_From_Bottom" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@style/dialog_animation</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowBackground">@android:color/transparent</item> </style> <style name="dialog_animation" parent="@android:style/Animation.Dialog"> <item name="android:windowEnterAnimation">@anim/push_bottom_in</item> <item name="android:windowExitAnimation">@anim/push_bottom_out</item> </style>
至于push_bottom_in.xml和push_bottom_out.xml见http://gundumw100.iteye.com/blog/2163571
0 0
- 基于上一篇写的UserBirthdayDialog
- 基于上一篇写的SimplePairListPopupWindow<F,S>
- 基于vue2写的上拉加载
- 基于vue2写的上拉加载
- 参考上一篇的资料写的去重程序
- 当年在《软件报》上写的一篇文章:…
- 我在csdn上写的第一篇博客
- 基于上一篇的红包算法的更改
- 基于上一篇文章的解压文件原理
- 基于上一篇自定义下拉刷新更新时间的SharedPreferencesHelper
- 基于上一篇实现的SimpleListPopupWindow<T>
- 第一次上CSDN上写一篇博客
- Android上,用mk文件调用C写的函数,承自上一篇(hellojni)
- 怒写一篇基于Windows10的最新ElasticSearch5.3的搜索引擎的开发博客(一)
- 怒写一篇基于Windows10的最新ElasticSearch5.3的搜索引擎的开发博客( 二)
- 在基于 Eclipse 的工具上写 Pixel Bender 语言
- 上一篇的思考
- 上一篇的后记
- 平台软件每日构建总结
- Axis2的OMElement问题
- 带标记的ImageView,图片可以设置成圆角
- java基础List、Set、Map
- 基于WheelView自定义的DatePickerDialog
- 基于上一篇写的UserBirthdayDialog
- 541. Reverse String II
- 实现一个快速简单的SimpleListDialog<T>
- Cookie和HttpSession
- 自定义Tablayout的布局
- 基于上一篇实现的SimpleListPopupWindow<T>
- 移动端常见的一些兼容性问题
- C++与类型转换相关的四个关键字及其特点
- 基于上一篇写的SimplePairListPopupWindow<F,S>