android-时间选择器
来源:互联网 发布:软件需求变更 编辑:程序博客网 时间:2024/06/13 23:33
参考网站:http://wear.techbrood.com/guide/topics/ui/controls/pickers.html
1、首先定义一个类DatePickerFragment继承DialogFragment,并实现接口DatePickerDialog.OnDateSetListener;
/** * Created by czz on 2016/4/1. */public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); return new DatePickerDialog(getActivity(),this,year,month, day); } @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Toast.makeText(getActivity(),year+"/" + monthOfYear + "/" + dayOfMonth,Toast.LENGTH_SHORT).show(); }}
2、布局一个按钮或其他控件
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="时间选择器" android:id="@+id/id_selectTime" android:layout_below="@+id/id_togglebtn" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="43dp" />
3、声明DialogFragment对象,调用show()方法
selectTime = (Button) findViewById(R.id.id_selectTime); selectTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment TimeDF = new DatePickerFragment(); TimeDF.show(getFragmentManager(),"datePicker"); } });
0 0
- [Android]时间选择器/日历选择器/选择器dialog
- android WheelView时间选择器
- 【android】时间选择器
- Android 自定义时间选择器
- android自定义时间选择器
- android 时间选择器
- android 时间选择器
- Android自定义时间选择器
- android-时间选择器
- Android时间选择器
- android 日期时间选择器
- Android 日期时间选择器
- Android自定义时间选择器
- Android的时间选择器
- android 时间选择器TimeSelector
- android 日期时间选择器
- Android 时间日期选择器
- Android 日期时间选择器
- php为图片填加水印
- 新闻轮播banner轮播解析
- 【hihocoder】hiho密码
- 方阵的生成、显示、检查
- Sqoop
- android-时间选择器
- 5.0以上移动数据的关闭
- 从零学习算法竞赛2:三整数排序
- 设计模式有感
- 函数原型和函数
- ubuntu 14.04 64位 桌面版 中文输入法安装
- boa.conf基本配置详解
- 算法#01--素数和牛顿迭代法求平方根
- c——————指针之易错点