Android中的日期选择器
来源:互联网 发布:特效软件有哪些 编辑:程序博客网 时间:2024/05/17 17:59
第一步:在MainActivity的代码:
package com.example.yangjian.learncomponents;import android.app.DatePickerDialog;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;import android.widget.DatePicker;public class chooseADate extends ActionBarActivity { private Button btnChooseDate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_choose_adate); btnChooseDate = (Button) findViewById(R.id.btnChooseDate); btnChooseDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(chooseADate.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String thedate = String.format("%d-%d-%d", monthOfYear+1, dayOfMonth); System.out.println(thedate); btnChooseDate.setText(thedate); } },2015,8,3).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_choose_adate, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
第二步:在xml文件中的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.example.yangjian.learncomponents.chooseADate"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0000-00-00" android:id="@+id/btnChooseDate"/></LinearLayout>
0 0
- Android中的日期选择器
- Github中的Android时间,日期选择器
- Android中的日期和时间选择器
- Android 日期选择器、日期范围选择器:MaterialDateRangePicker
- android 日期选择器
- android 日期滑动选择器
- Android日期选择器
- android 日期选择器
- Android 万年历日期选择器
- Android日期选择器用法
- Android的日期选择器
- Android 之 日期选择器
- android 日期时间选择器
- Android自定义日期选择器
- Android 日期时间选择器
- android 日期时间选择器
- android 日期选择器
- Android 自定义日期选择器
- 【Objective-C编程】 Must explicitly describe intended ownership of an object array parameter异常报错解决方案
- 文章标题
- 序列的自相关和互相关计算
- 并查集
- UVA 537 Artificial Intelligence?
- Android中的日期选择器
- JAVA设计模式之工厂模式 代码是原创
- protobuf+vs2013编译安装
- Java NIO框架Netty教程(四) – ServerBootStrap启动流程源码分析
- Android GetStringUTFRegion()
- hadoop最新环境信息
- eclipse 按ctrl建只能显示一个方法的解决
- svn: Can't convert string from 'UTF-8' to native encoding 解决方法
- 前端电源