Android DatePickerDialog TimepickerDialog

來源:互聯網
上載者:User

標籤:

 1 package com.example.myact5; 2  3 import java.util.Calendar; 4  5 import android.app.DatePickerDialog; 6 import android.app.DatePickerDialog.OnDateSetListener; 7 import android.app.TimePickerDialog; 8 import android.app.TimePickerDialog.OnTimeSetListener; 9 import android.os.Bundle;10 import android.support.v7.app.ActionBarActivity;11 import android.view.View;12 import android.view.View.OnClickListener;13 import android.widget.Button;14 import android.widget.DatePicker;15 import android.widget.TimePicker;16 import android.widget.Toast;17 /**18  * 19  * @Describe: 20  * @package: com.example.myact521  * @author shaobn22  * @date 2015-9-11 上午9:10:2823  */24 public class MainActivity extends ActionBarActivity {25     private Button button;26     private Button button2;27     private Calendar calendar = Calendar.getInstance();28     @Override29     protected void onCreate(Bundle savedInstanceState) {30         super.onCreate(savedInstanceState);31         setContentView(R.layout.activity_main);32         button = (Button) this.findViewById(R.id.button1);33         button2 = (Button) this.findViewById(R.id.button2);34         button.setOnClickListener(new OnClickListener() {35             36             @Override37             public void onClick(View arg0) {38                 // TODO Auto-generated method stub39             TimePickerDialog tpd = new TimePickerDialog(MainActivity.this, new OnTimeSetListener() {40                 41                 @Override42                 public void onTimeSet(TimePicker arg0, int arg1, int arg2) {43                     // TODO Auto-generated method stub44                     Toast.makeText(MainActivity.this,getConstantInstance().hourOfDay+","+ getConstantInstance().minute, 1).show();45                 }46             }, getConstantInstance().hourOfDay, getConstantInstance().minute, true);    47             tpd.show();48             }49         });50         button2.setOnClickListener(new OnClickListener() {51             52             @Override53             public void onClick(View arg0) {54                 // TODO Auto-generated method stub55                 DatePickerDialog dpd = new DatePickerDialog(MainActivity.this, new OnDateSetListener() {56                     57                     @Override58                     public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {59                         // TODO Auto-generated method stub60                         Toast.makeText(MainActivity.this, arg1+","+(arg2+1)+","+arg3, 1).show();61                     }62                 }, getConstantInstance().year, getConstantInstance().monthOfYear, getConstantInstance().dayOfMonth);63                 dpd.show();64             }65         });66     }    67     class Constant{68         public int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);69         public int minute = calendar.get(Calendar.MINUTE);70         public boolean is24HourView = true;71         public int year = calendar.get(Calendar.YEAR);72         public int monthOfYear = calendar.get(Calendar.MONTH);73         public int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);74     }75     public Constant getConstantInstance(){76         return new Constant();77     }78 }

筆者寫的麻煩點,為了練習一下。

Android DatePickerDialog TimepickerDialog

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.