滑轮选择,WheelView的简单使用
来源:互联网 发布:淘宝买管制刀具 编辑:程序博客网 时间:2024/05/01 06:40
简单粗暴,直接上图
主要的代码解析很清楚
当然,并没有去写调用系统的时间,所以就随便复制点常量搞上了
package com.example.wheelviewtext;import org.w3c.dom.Text;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.LinearLayout;import android.widget.TextView;public class MainActivity extends Activity {//定义常量数据private String[] Week={"周一","周二","周三","周四","周五","周六","周日"};private String[] Month={"1","2","3","4","5","6","7","8","9","10","11","12"};private String[] Day={"1","2","3","4","5","6","7","8","9","10" ,"11","12","13","14","15","16","17","18","19","20" ,"21","22","23","24","25","26","27","28","29","30","31"};private String[] Month_Day_Week=new String[365];private int Week_Count=3;private int k=0;private String[] Hour={"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};private String[] Minute={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"};//数据初始化public void init(){for(int i=0;i<12;i++){for(int j=0;j<31;j++){//2月,暂不考虑闰年if(i==1&&j>27)break;if((i==3||i==5||i==8||i==10)&&j>29)break;Week_Count%=7;Month_Day_Week[k++]=new String(Month[i]+"月"+Day[j]+"日"+Week[Week_Count++]);}}}private Button btn;private TextView text; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化调用 init(); btn = (Button) findViewById(R.id.btn); text=(TextView) findViewById(R.id.text); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showSelectDialog(MainActivity.this, "日期选择", Month_Day_Week, Hour,Minute); } }); } //布局及显示的自定义函数 private void showSelectDialog(Context context, String title, final String[] Month_Day_Week, final String[] Hour,final String Minute[]) { //定义布局控件 AlertDialog dialog = new AlertDialog.Builder(context).create(); dialog.setTitle(title); LinearLayout llContent = new LinearLayout(context); llContent.setOrientation(LinearLayout.HORIZONTAL); //定义月日周的WheelView final WheelView wheelMonth = new WheelView(context); //画面显示个数 wheelMonth.setVisibleItems(5); wheelMonth.setCyclic(true); /*设置监听布局 第一个参数为对应为传入的数据,第二个参数为初始化显示字节最大长度 一个字为2字节,一个数字为1字节 以最大为标准 12月30日周日 4个字8字节,4个数字4字节 共12字节 */ wheelMonth.setAdapter(new ArrayWheelAdapter<String>(Month_Day_Week,12)); //定义小时 final WheelView wheelHour = new WheelView(context); wheelHour.setVisibleItems(5); wheelHour.setCyclic(true); wheelHour.setAdapter(new ArrayWheelAdapter<String>(Hour,2)); //定义分钟 final WheelView wheelMinute=new WheelView(context); wheelMinute.setVisibleItems(5); wheelMinute.setCyclic(true); wheelMinute.setAdapter(new ArrayWheelAdapter<String>(Minute,2)); //月日周的显示容器 LinearLayout.LayoutParams paramsMonth = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, (float) 2.0); paramsMonth.gravity = Gravity.LEFT; //时的显示容器 LinearLayout.LayoutParams paramsHour = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, (float) 0.5); paramsHour.gravity = Gravity.CENTER; //分钟的显示容器 LinearLayout.LayoutParams paramsMinute = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, (float) 0.5); paramsMinute.gravity = Gravity.RIGHT; //分别添加View进入各自的容器 llContent.addView(wheelMonth, paramsMonth); llContent.addView(wheelHour, paramsHour); llContent.addView(wheelMinute,paramsMinute); //设置Month改变监听 wheelMonth.addChangingListener(new OnWheelChangedListener() { @Override public void onChanged(WheelView wheel, int oldValue, int newValue) { } }); //小时的监听器 wheelHour.addChangingListener(new OnWheelChangedListener() {@Overridepublic void onChanged(WheelView wheel, int oldValue, int newValue) {// TODO Auto-generated method stub}}); //分钟的监听器 wheelMinute.addChangingListener(new OnWheelChangedListener() {@Overridepublic void onChanged(WheelView wheel, int oldValue, int newValue) {// TODO Auto-generated method stub}}); //按钮触发事件 dialog.setButton(AlertDialog.BUTTON_POSITIVE, "确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int leftPosition = wheelMonth.getCurrentItem(); String vMonth = Month_Day_Week[leftPosition]; String vHour = Hour[wheelHour.getCurrentItem()]; String vMinute=Minute[wheelMinute.getCurrentItem()]; text.setText(vMonth + "-" + vHour+":"+vMinute); dialog.dismiss(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); //总布局显示,对话框 dialog.setView(llContent); if (!dialog.isShowing()) { dialog.show(); } } }
(eclipse)代码:http://pan.baidu.com/s/1o6tGXlg
0 0
- 滑轮选择,WheelView的简单使用
- android: WheelView组件(滑轮组件)的应用!
- android: WheelView组件(滑轮组件)的应用!
- 漂亮的时间日期选择 wheelView
- 点击Dialog弹出WheelView滑轮效果源码
- 滚动选择WheelView
- WheelView滚动选择控件
- wheelview实现日历选择
- 学习笔记:实现二维的滚动选择控件WheelView
- Android使用wheelView实现简单类似ios PickerView选择器效果
- CSS+JS经典的滑轮新闻显示 选择卡
- Android滑动选择控件 WheelView
- 滑轮控件的研究五、ViewConfiguration的简单介绍
- 滑轮控件的研究五、ViewConfiguration的简单介绍
- 滑轮控件的研究五、ViewConfiguration的简单介绍
- 滑轮控件的研究五、ViewConfiguration的简单介绍
- 滑轮控件的研究-ViewConfiguration的简单介绍
- 滑轮控件研究四、VelocityTracker的简单研究
- OpenCV中GPU模块使用
- Android.mk文件语法规范(Android.mk File)
- Xcode5发布企业版app
- C++中的substr()和find()
- 华为机试——将一个字符串的元音字母复制到另一个字符串,并排序
- 滑轮选择,WheelView的简单使用
- Web Service相关规范
- android intent 用法
- C++的errorC2039和C2679的解决
- 代理中触发表单按钮
- JQuery选择器大全
- SpringMVC jpa 分页问题
- iOS使用UIScrollerView进行图片缩放,实现仿新闻图片阅读功能
- zookeeper四字命令