基本信息
源码名称:andriod滚轮选择生日 例子源码下载
源码大小:1.08M
文件格式:.zip
开发语言:Java
更新时间:2015-04-21
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
public class MainActivity extends Activity{ private View contentView; private int yy, mm, dd; private String cyy, cmm, cdd; private boolean scrolling = false; private Dialog alertDialog; private Button button_ok; TextView show_birth; RelativeLayout relat; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); relat=(RelativeLayout)findViewById(R.id.ralat_tiaozhuan); show_birth=(TextView)findViewById(R.id.show_birth); relat.setOnClickListener(tiao); } OnClickListener tiao=new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub enterDialg(); } }; @SuppressLint("NewApi") private void enterDialg() { contentView = View.inflate(getApplicationContext(), R.layout.select_birthday, null); contentView.startAnimation(AnimationUtils.loadAnimation( MainActivity.this, R.anim.fade_ins)); LinearLayout ll_shopping_detail_history_ll = (LinearLayout) contentView .findViewById(R.id.ll_select_birthday_ll); ll_shopping_detail_history_ll.startAnimation(AnimationUtils .loadAnimation(MainActivity.this, R.anim.push_bottom_in_2)); Calendar calendar = Calendar.getInstance(); final WheelView month = (WheelView) contentView .findViewById(R.id.month); final WheelView year = (WheelView) contentView.findViewById(R.id.year); final WheelView day = (WheelView) contentView.findViewById(R.id.day); OnWheelChangedListener listener = new OnWheelChangedListener() { public void onChanged(WheelView wheel, int oldValue, int newValue) { updateDays(year, month, day); } }; // month int curMonth = calendar.get(Calendar.MONTH); String months[] = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; month.setViewAdapter(new DateArrayAdapter(this, months, curMonth)); month.setCurrentItem(mm); cmm = month.getCurrentItem() 1 ""; System.out.println("cmm查看 >" cmm); System.out.println("mm查看 >" mm); month.addChangingListener(listener); month.addScrollingListener(new OnWheelScrollListener() { @Override public void onScrollingStarted(WheelView wheel) { // TODO Auto-generated method stub scrolling = true; System.out.println("============执行true============"); } @Override public void onScrollingFinished(WheelView wheel) { // TODO Auto-generated method stub scrolling = false; cmm = month.getCurrentItem() 1 ""; System.out.println("============执行fase============"); } }); // year final int curYear = calendar.get(Calendar.YEAR); System.out.println("年=============================>" curYear); year.setViewAdapter(new DateNumericAdapter(this, curYear - 10, curYear 100, 0)); yy=curYear - 10; year.setCurrentItem(yy); Log.e("yy", yy - (curYear - 10) ""); cyy = yy ""; System.out.println("cyy查看 >" cyy); System.out.println("yy查看 >" yy); year.addChangingListener(listener); year.addScrollingListener(new OnWheelScrollListener() { @Override public void onScrollingStarted(WheelView wheel) { // TODO Auto-generated method stub scrolling = true; } @Override public void onScrollingFinished(WheelView wheel) { // TODO Auto-generated method stub scrolling = false; cyy = year.getCurrentItem() (curYear - 10) ""; System.out.println("查看=====================>" year.getCurrentItem()); } }); // day updateDays(year, month, day); day.setCurrentItem(dd); cdd = day.getCurrentItem() 1 ""; alertDialog = new Dialog(MainActivity.this, R.style.CustomDialog); day.addScrollingListener(new OnWheelScrollListener() { @Override public void onScrollingStarted(WheelView wheel) { // TODO Auto-generated method stub scrolling = true; } @Override public void onScrollingFinished(WheelView wheel) { // TODO Auto-generated method stub scrolling = false; cdd = day.getCurrentItem() 1 ""; } }); Window win = alertDialog.getWindow(); // LayoutParams params = new LayoutParams(); // params.x = -150;// 设置x坐标 // params.y = -220;// 设置y坐标 // win.setAttributes(params); win.setGravity(Gravity.BOTTOM); alertDialog.setContentView(contentView); WindowManager.LayoutParams lp = win.getAttributes(); lp.width = LayoutParams.FILL_PARENT; // lp.height = LayoutParams.FILL_PARENT; win.setAttributes(lp); alertDialog.show(); button_ok = (Button) contentView.findViewById(R.id.button_ok1); button_ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub alertDialog.dismiss(); show_birth.setText(cyy "-" cmm "-" cdd); } }); ll_shopping_detail_history_ll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // alertDialog.dismiss(); } }); } /** * Updates day wheel. Sets max days according to selected month and year */ void updateDays(WheelView year, WheelView month, WheelView day) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) year.getCurrentItem()); calendar.set(Calendar.MONTH, month.getCurrentItem()); int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); day.setViewAdapter(new DateNumericAdapter(this, 1, maxDays, calendar .get(Calendar.DAY_OF_MONTH) - 1)); int curDay = Math.min(maxDays, day.getCurrentItem() 1); day.setCurrentItem(curDay - 1, true); } /** * Adapter for numeric wheels. Highlights the current value. */ private class DateNumericAdapter extends NumericWheelAdapter { // Index of current item int currentItem; // Index of item to be highlighted int currentValue; /** * Constructor */ public DateNumericAdapter(Context context, int minValue, int maxValue, int current) { super(context, minValue, maxValue); this.currentValue = current; setTextSize(16); } @Override protected void configureTextView(TextView view) { super.configureTextView(view); // if (currentItem == currentValue) { // view.setTextColor(0xFF0000F0); // } view.setTypeface(Typeface.SANS_SERIF); } @Override public View getItem(int index, View cachedView, ViewGroup parent) { currentItem = index; return super.getItem(index, cachedView, parent); } } /** * Adapter for string based wheel. Highlights the current value. */ private class DateArrayAdapter extends ArrayWheelAdapter<String> { // Index of current item int currentItem; // Index of item to be highlighted int currentValue; /** * Constructor */ public DateArrayAdapter(Context context, String[] items, int current) { super(context, items); this.currentValue = current; setTextSize(16); } @Override protected void configureTextView(TextView view) { super.configureTextView(view); // if (currentItem == currentValue) { // view.setTextColor(0xFF0000F0); // } view.setTypeface(Typeface.SANS_SERIF); } @Override public View getItem(int index, View cachedView, ViewGroup parent) { currentItem = index; return super.getItem(index, cachedView, parent); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }