在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Android平台开发 → andriod滚轮选择生日 例子源码下载

andriod滚轮选择生日 例子源码下载

Android平台开发

下载此实例
  • 开发语言:Java
  • 实例大小:1.08M
  • 下载次数:14
  • 浏览次数:243
  • 发布时间:2015-04-21
  • 实例类别:Android平台开发
  • 发 布 人:闲贤
  • 文件格式:.zip
  • 所需积分:3
 相关标签:

实例介绍

【实例简介】

【实例截图】

【核心代码】

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;
	}

}

标签:

实例下载地址

andriod滚轮选择生日 例子源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警