zoukankan      html  css  js  c++  java
  • Android DatePickerDialog

    一.源码

        public DatePickerDialog(@NonNull Context context, @Nullable DatePickerDialog.OnDateSetListener listener, int year, int month, int dayOfMonth) {
            super((Context)null);
            throw new RuntimeException("Stub!");
        }
      //int themeResId  样式
        public DatePickerDialog(@NonNull Context context, int themeResId, @Nullable DatePickerDialog.OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth) {
            super((Context)null);
            throw new RuntimeException("Stub!");
        }  

    二.代码

    eclipse、as 同方法也有可能不同样式,取决于清单文件

    2.1.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/idtatabHost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >
    
        <Button
            android:id="@+id/btn_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="点我一下 挑日期" />
    
        <Button
            android:id="@+id/btn_ok"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="点我一下 挑时间 。。。" />
    
    </LinearLayout>

    2.2.eclipse

    package com.gatsby.datepickerdialogtest2;
    
    import java.util.Calendar;
    
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class MainActivity extends Activity implements OnClickListener {
    	private Button btn_date;
    	private Button btn_ok;
    	Context mContext;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    
    		mContext = MainActivity.this;
    		btn_date = (Button) findViewById(R.id.btn_date);
    		btn_date.setOnClickListener(this);
    
    	}
    
    	@Override
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		switch (v.getId()) {
    		case R.id.btn_date:
    			// 弹出对话框
    			Calendar calendar = Calendar.getInstance();
    			DatePickerDialog datePickerDialog = new DatePickerDialog(mContext, null, calendar.get(Calendar.YEAR),
    					calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    			datePickerDialog.show();
    			break;
    		}
    	}
    
    }
    

    2.3.AS 

    package com.gatsby.test3;
    
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.DatePicker;
    
    import java.util.Calendar;
    
    public class MainActivity extends Activity implements View.OnClickListener , DatePickerDialog.OnDateSetListener {
    
    
        private Button btn_date;
        private Button btn_ok;
        Context mContext;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mContext = MainActivity.this;
            btn_date = (Button) findViewById(R.id.btn_date);
            btn_date.setOnClickListener(this);
    
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
                case R.id.btn_date:
                    // 弹出对话框
                    Calendar calendar = Calendar.getInstance();
                    DatePickerDialog datePickerDialog = new DatePickerDialog(mContext, 3,this, calendar.get(Calendar.YEAR),
                            calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
                    datePickerDialog.show();
                    break;
            }
        }
    
        @Override
        public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
    
        }
    }
    

      

  • 相关阅读:
    cmd启动数据库时,出现 (无法启动此程序,因为计算机中丢失VCRUNTIME140_1.dll 尝试重新安装此程序以解决此问题 )解决方法。
    浅谈Promise语法API+封装
    浅谈JS回调地狱
    MySQL数据库安装步骤
    将MongoDB安装为Windows服务---安装MongoDB服务
    后缀.msc文件是什么?
    Mongoose类库使用教程---实现增删改查
    MongoDB可视化工具--Robo 3T 安装使用教程
    久违的锻炼
    出差(2~十四)
  • 原文地址:https://www.cnblogs.com/crushgirl/p/14700316.html
Copyright © 2011-2022 走看看