zoukankan      html  css  js  c++  java
  • 2.5.5 使用DatePickerDialog, TimePickerDialog

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/btnTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="时间选择" />
    
        <Button
            android:id="@+id/btnDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="日期选择" />
    
        <TextView
            android:id="@+id/show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="" >
            
        </TextView>
    
    </LinearLayout>
    package com.moon.hello2;
    
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.zip.Inflater;
    
    import android.R.anim;
    import android.R.bool;
    import android.R.integer;
    import android.animation.AnimatorSet.Builder;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.DatePickerDialog;
    import android.app.DatePickerDialog.OnDateSetListener;
    import android.app.TimePickerDialog.OnTimeSetListener;
    import android.app.Dialog;
    import android.app.TimePickerDialog;
    import android.content.DialogInterface;
    import android.content.res.TypedArray;
    import android.database.DataSetObserver;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.Gravity;
    import android.view.Menu;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup.LayoutParams;
    import android.view.animation.AnimationUtils;
    import android.widget.AbsListView;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    import android.widget.BaseAdapter;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.ExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.LinearLayout;
    import android.widget.ListView;
    import android.widget.PopupWindow;
    import android.widget.ProgressBar;
    import android.widget.RatingBar;
    import android.widget.SimpleAdapter;
    import android.widget.TableLayout;
    import android.widget.RatingBar.OnRatingBarChangeListener;
    import android.widget.SeekBar;
    import android.widget.DatePicker.OnDateChangedListener;
    import android.widget.SeekBar.OnSeekBarChangeListener;
    import android.widget.TabHost;
    import android.widget.TextView;
    import android.widget.TimePicker;
    import android.widget.TimePicker.OnTimeChangedListener;
    import android.widget.ViewSwitcher.ViewFactory;
    
    public class MainActivity extends Activity {
        private final String[] colorStrings = new String[] { "红色", "绿色", "黄色" };
        private static final int DIALOG_SC = 1;
        private final boolean[] checkStatus = new boolean[] { true, true, false };
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            this.setContentView(R.layout.activity_main);
            final Calendar calendar = Calendar.getInstance();
            final TextView showTextView = (TextView) findViewById(R.id.show);
            findViewById(R.id.btnDate).setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    new DatePickerDialog(MainActivity.this,
                            new OnDateSetListener() {
    
                                @Override
                                public void onDateSet(DatePicker arg0, int year,
                                        int month, int date) {
                                    // TODO Auto-generated method stub
                                    showTextView.setText("选择的日期是" + year + "年"
                                            + month + "月" + date + "日");
                                }
                            }, calendar.get(Calendar.YEAR), calendar
                                    .get(Calendar.MONTH), calendar
                                    .get(calendar.DATE)).show();
                }
            });
            findViewById(R.id.btnTime).setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    new TimePickerDialog(MainActivity.this,
                            new OnTimeSetListener() {
    
                                @Override
                                public void onTimeSet(TimePicker arg0, int hour,
                                        int minute) {
                                    // TODO Auto-generated method stub
                                    showTextView.setText("选择的时间为" + hour + "小时"
                                            + minute + "分");
                                }
                            }, calendar.get(Calendar.HOUR), calendar
                                    .get(Calendar.MINUTE), true).show();
                }
            });
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    }
  • 相关阅读:
    两数之和
    输入一个int型数据,计算出该int型数据在内存中存储时1的个数。
    MySQL事务机制(Transaction)
    JAVA 之 深入理解String类
    MySQL 之 SQL练习
    python常用函数及循环
    python多版本配置pyenv
    ES6语法的简单示例
    学习笔记190—利用matlab求解方程组的解
    学习笔记189—pandas 获取Dataframe元素值的几种方法
  • 原文地址:https://www.cnblogs.com/Moon-Face/p/4530880.html
Copyright © 2011-2022 走看看