没什么技术含量,参考别人的代码,简单的实现对话框的展示,设置日期时间。

其中设置日期时,默认的月份为month-1的

代码

package com.nico;import android.app.Activity;import android.app.DatePickerDialog;//import android.app.TimePickerDialog;import android.app.Dialog;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.DatePicker;//import android.widget.TimePicker;public class timePicker extends Activity {/** Called when the activity is first created. */private Button ShowDataPickerButton = null;private static final int DATA_PICKER_ID = 1;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.data);ShowDataPickerButton = (Button) findViewById(R.id.ShowDataPickerButton);ShowDataPickerButton.setOnClickListener(new ShowClickListener());}private class ShowClickListener implements OnClickListener {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubshowDialog(DATA_PICKER_ID);}}DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {Log.v("Test", "-------------?"+year);System.out.print(year + " " + monthOfYear + "  " + dayOfMonth);}};//TimePickerDialog.OnTimeSetListener onTimeSetListener = new TimePickerDialog.OnTimeSetListener() {////@Override//public void onTimeSet(TimePicker view, int hourOfDay, int minute) {//// TODO Auto-generated method stub//System.out.println(hourOfDay + "-" + minute);//}////};@Overrideprotected Dialog onCreateDialog(int id) {// TODO Auto-generated method stubswitch (id) {case DATA_PICKER_ID:Log.v("Test", "--------start---------->");return new DatePickerDialog(this, onDateSetListener, 2011, 01, 01);// return new TimePickerDialog(this,onTimeSetListener,22,3, true);}return super.onCreateDialog(id);}}

xml

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:orientation="vertical"      android:layout_width="fill_parent"      android:layout_height="fill_parent"      >  <TextView        android:layout_width="fill_parent"       android:layout_height="wrap_content"       android:text="@string/hello"      />         <Button         android:id="@+id/ShowDataPickerButton"         android:layout_width="fill_parent"          android:layout_height="wrap_content"        />              </LinearLayout>

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. Python3原生编写月份计算工具
  3. android studio信鸽推送10004错误
  4. Android(安卓)APK JNI sample (JAVA JNI)
  5. android studio 打包jar 及混淆
  6. getLayoutInflater().inflate
  7. Android中在代码中设置控件的宽和高
  8. 通过手势实现Android(安卓)ImageView 缩放
  9. GPS在Android的使用

随机推荐

  1. Google Play Services to Beat Android(
  2. [Android]Tab
  3. Android推送通知
  4. How to build and debug android source
  5. android中的ImageButton
  6. Android中Broadcast的Intent大全
  7. android Bitmap->BGR字节数组
  8. android anr
  9. Android(安卓)头像修改
  10. Android日历