自定义Dialog

 

此代码完成一个带有日期和时间功能的Dialog

效果图如下:

自定义Dialog

     AlertDialog.Builder  builder = new AlertDialog.Builder(MeettingManage_1.this);   

  LayoutInflater factory = LayoutInflater.from(MeettingManage_1.this);  

     final View textEntryView = factory.inflate(R.layout.meettime_date_dialog, null);      

     builder.setTitle("选择时间");      

     builder.setView(textEntryView);      

     builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

                                               public void onClick(DialogInterface dialog, int whichButton) {

                                                        TimePicker timePicker = (TimePicker)textEntryView.findViewById(R.id.timepicker);

                                                        DatePicker datePicker = (DatePicker)textEntryView.findViewById(R.id.datepicker);

                                                        timeEditText.setText(datePicker.getYear()+"-"+(datePicker.getMonth()+1)+"-"+datePicker.getDayOfMonth()+"     "+timePicker.getCurrentHour()+":"+timePicker.getCurrentMinute()+"");

                                                        }      

                                               });

                                     builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

                                               public void onClick(DialogInterface dialog, int whichButton) {

                                                       

                                               }      

                                               });    

                                     builder.create().show();

XML文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="#e6f5fa"

    android:orientation="vertical" >

 

    <TimePicker

          android:id="@+id/timepicker"

          android:layout_width="wrap_content"

          android:layout_height="wrap_content"/>

       <DatePicker

              android:id="@+id/datepicker"

          android:layout_width="wrap_content"

          android:layout_height="wrap_content" />

</LinearLayout>

你可能感兴趣的:(dialog)