zoukankan      html  css  js  c++  java
  • android 获取Datepicker日期

    1.使用的Android5.0系统,实现上面效果使用了alertdialog

    2.布局文件: layout_dataselect

    <?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">
        <DatePicker
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:id="@+id/datepicker1"
            android:calendarViewShown="false"     //  使得控件不会出现 日历样式
            android:datePickerMode="spinner"            // 使得控件不会使用5.0新样式
            />
    </LinearLayout>
    

      

    2.主布局加一个Button,textView即可:

    3.

     textView_datastart.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder localBuilder = new AlertDialog.Builder(WenjianSearch_Activity.this);
                    localBuilder.setTitle("选择时间").setIcon(R.mipmap.ic_launcher);
                    //
                    final LinearLayout layout_alert= (LinearLayout) getLayoutInflater().inflate(R.layout.layout_dataselect, null);
                    localBuilder.setView(layout_alert);
                    localBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener()
                    {
                        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
                        {
                            DatePicker datepicker1= (DatePicker) layout_alert.findViewById(R.id.datepicker1);
                            int y=datepicker1.getYear();
                            int m=datepicker1.getMonth()+1;
                            int d=datepicker1.getDayOfMonth();
                            System.out.println("y:"+y+" m:"+m+" d:"+d);
                            textView_datastart.setText(y+"-"+m+"-"+d); //  获取时间
    
    
                        }
                    }).setNegativeButton("取消", new DialogInterface.OnClickListener()
                    {
                        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
                        {
    
                        }
                    }).create().show();
                }
            });
    

      

    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”
    未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包
    重装VS2010时出现未能正确加载 "radlangsvc.package,radlangsvc.vs...
    page.Response.WriteFile(newpath);
    Response.ContentType 详细列表 <转>
    创建存储过程,使用游标更新表信息
    淘宝顶端的通知样式 .
    ssm整合各配置文件
    XSS-Labs(Level1-10)
    局域网技术
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/6184425.html
Copyright © 2011-2022 走看看