Android Studio 日期选择器 及日期对话框

Android Studio 日期选择器 及日期对话框,第1张

概述AndroidStudio日期选择器及日期对话框activity_main.xml<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"android:layout_width="match_parent"

AndroID Studio 日期选择器 及日期对话框
activity_main.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"    >    <TextVIEw        androID:text="Hello World!"        androID:layout_gravity="center"        androID:ID="@+ID/tv"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/>    <DatePicker        androID:layout_margintop="50dp"        androID:layout_gravity="center"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/>    <button        androID:layout_gravity="center"        androID:layout_margintop="10dp"        androID:text="按钮"        androID:ID="@+ID/bt"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"/></linearLayout>

MainActivity.java

package com.easybooks.myapplication;import androIDx.appcompat.app.AlertDialog;import androIDx.appcompat.app.AppCompatActivity;import androID.app.DatePickerDialog;import androID.content.DialogInterface;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.DatePicker;import androID.Widget.TextVIEw;import java.util.Calendar;public class MainActivity extends AppCompatActivity {    private TextVIEw textVIEw;    private button button;    private String decs;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        textVIEw = findVIEwByID(R.ID.tv);        button = findVIEwByID(R.ID.bt);        button.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                Calendar calendar = Calendar.getInstance();                DatePickerDialog dialog = new DatePickerDialog(MainActivity.this,                        new DatePickerDialog.OnDateSetListener() {                            @OverrIDe                            public voID onDateSet(DatePicker vIEw, int year, int month, int dayOfMonth) {                                 decs = String.format("%d %d %d", year, month, dayOfMonth);                            }                        },                        calendar.get(Calendar.YEAR),                        calendar.get(Calendar.MONTH),                        calendar.get(Calendar.DAY_OF_MONTH));                dialog.show();                textVIEw.setText(decs);            }        });        AlertDialog.Builder builder = new AlertDialog.Builder(this);        builder.setTitle("hello world");        builder.setMessage("hello world");        builder.setPositivebutton("确定", new DialogInterface.OnClickListener() {            @OverrIDe            public voID onClick(DialogInterface dialog, int which) {            }        });        AlertDialog alter = builder.create();        alter.show();    }}


总结

以上是内存溢出为你收集整理的Android Studio 日期选择器 及日期对话框全部内容,希望文章能够帮你解决Android Studio 日期选择器 及日期对话框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1004428.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存