zoukankan      html  css  js  c++  java
  • Android DatePickerDialog用法

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/text01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="查询日期:"
            android:textSize="18sp"
            />
        <TextView 
            android:id="@+id/tvDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/text01"
            android:layout_alignLeft="@id/text01"
            />
        <Button 
            android:id="@+id/btnDatePicker"
            android:text="编辑"
            android:layout_toRightOf="@id/tvDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="show"
            android:layout_alignTop="@id/tvDate"
            />
    </RelativeLayout>
    
    package com.turboradio;
    
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.DatePicker;
    import android.widget.TextView;
    
    public class DatePickerActivity extends Activity {
    	private TextView tvDate;
    	private Calendar cal = Calendar.getInstance();
    	private DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
    		
    		@Override
    		public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
    			cal.set(Calendar.YEAR, year);
    			cal.set(Calendar.MONTH, monthOfYear);
    			cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    			updateDate();
    		}
    	};
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.date_picker_dialog);
    		tvDate = (TextView)findViewById(R.id.tvDate);
    		
    	}
    	public void show(View v){
    		new DatePickerDialog(DatePickerActivity.this,listener,
    				cal.get(Calendar.YEAR),
    				cal.get(Calendar.MONTH),
    				cal.get(Calendar.DAY_OF_MONTH)
    				).show();
    	}
    	private void updateDate(){
    		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    		tvDate.setText(simpleDateFormat.format(cal.getTime()));
    	}
    }
    
  • 相关阅读:
    node安装依赖
    Redis高可用持久化方案选择
    分布式系统的一致性和幂等性概念
    Yii2 layout 由 controller 向layout中传递参数值
    Yii2 中 checkboxlist 复选框 默认选中
    centos 搭建redis主从
    php 魔术方法 __call
    vargrant 安装 CentOS-7-x86_64
    MyISAM与innoDB存储引擎有何差别
    centos PHP7 yii2 报错 Call to undefined function yii\helpers\mb_strlen()
  • 原文地址:https://www.cnblogs.com/jiayonghua/p/2334713.html
Copyright © 2011-2022 走看看