日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android datepicker 自定义,android – 如何使用两个datepicker创建自定义对话框?

發布時間:2025/3/8 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android datepicker 自定义,android – 如何使用两个datepicker创建自定义对话框? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最好先閱讀

Dialogs和

Pickers.

至于實現,您可以有兩個按鈕:一個用于顯示開始日期的日期選擇器,另一個用于顯示結束日期.

編輯:如果你真的想在1個對話框中顯示2個日期選擇器,這里有一個如何做的例子.首先,創建自定義XML布局.

/res/layout/custom_date_picker.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/dpStartDate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:calendarViewShown="false" />

android:id="@+id/dpEndDate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:calendarViewShown="false" />

接下來是在對話框中使用上面的布局:

// These variables will hold the date values later

private int startYear,startMonth,startDay,endYear,endMonth,endDay;

/**

* Displays the start and end date picker dialog

*/

public void showDatePicker() {

// Inflate your custom layout containing 2 DatePickers

LayoutInflater inflater = (LayoutInflater) getLayoutInflater();

View customView = inflater.inflate(R.layout.custom_date_picker,null);

// Define your date pickers

final DatePicker dpStartDate = (DatePicker) customView.findViewById(R.id.dpStartDate);

final DatePicker dpEndDate = (DatePicker) customView.findViewById(R.id.dpEndDate);

// Build the dialog

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

builder.setView(customView); // Set the view of the dialog to your custom layout

builder.setTitle("Select start and end date");

builder.setPositiveButton("OK",new DialogInterface.OnClickListener(){

@Override

public void onClick(DialogInterface dialog,int which) {

startYear = dpStartDate.getYear();

startMonth = dpStartDate.getMonth();

startDay = dpStartDate.getDayOfMonth();

endYear = dpEndDate.getYear();

endMonth = dpEndDate.getMonth();

endDay = dpEndDate.getDayOfMonth();

dialog.dismiss();

}});

// Create and show the dialog

builder.create().show();

}

最后,您只需調用showDatePicker()即可顯示此對話框.

總結

以上是生活随笔為你收集整理的android datepicker 自定义,android – 如何使用两个datepicker创建自定义对话框?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。