欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

基于WheelView自定義的DatePickerDialog

系統 1655 0
本人利用WheelView寫的一個DatePickerDialog
(還有一個TimePickerDialog,本人忘了在寫在哪個項目里了,等找到了也貼上來)

先看圖,有個直觀的了解

基于WheelView自定義的DatePickerDialog


DatePickerDialog代碼:
    
import java.util.Calendar;

import com.widget.wheel.NumericWheelAdapter;
import com.widget.wheel.OnWheelScrollListener;
import com.widget.wheel.WheelView;
import com.yirui.youbao.app.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * 
 * @author pythoner
 * 
 */
public class DatePickerDialog extends Dialog
{

    private Button btn_left, btn_right;

    private WheelView year, month, day;

    private String date;//初始化顯示的日期,默認為當日

    public DatePickerDialog(Context context, String date)
    {
//        super(context);
        this(context, R.style.Theme_Dialog_NoTitle, date);
        // TODO Auto-generated constructor stub
    }

    public DatePickerDialog(Context context, int theme, String date)
    {
        super(context, theme);
        // TODO Auto-generated constructor stub
        this.date = date;
        init();
    }

    private void init()
    {
        this.setCanceledOnTouchOutside(true);
        this.setCancelable(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_date_picker);

        initViews();
        initValues();
    }

    private void initViews()
    {
        btn_left = (Button) findViewById(R.id.btn_left);
        btn_left.setOnClickListener(clickListener);
        btn_right = (Button) findViewById(R.id.btn_right);
        btn_right.setOnClickListener(clickListener);

        String icurYear, icurMonth, icurDay;
        Calendar c = Calendar.getInstance();
        int curYear = c.get(Calendar.YEAR);
        if (date == null || date.length() < 10)
        {// 格式不正確
            int curMonth = c.get(Calendar.MONTH);
            int curDay = c.get(Calendar.DAY_OF_MONTH);
            icurYear = String.valueOf(curYear);
            icurMonth = String.valueOf(curMonth + 1);
            icurDay = String.valueOf(curDay);
        }
        else
        {// 年月日
            icurYear = date.substring(0, 4);
            icurMonth = date.substring(5, 7);
            icurDay = date.substring(8, 10);
        }

        year = (WheelView) findViewById(R.id.year);
        year.setAdapter(new NumericWheelAdapter(curYear - 2, curYear));
        // year.setLabel("年");
        year.setCurrentItem(Integer.parseInt(icurYear) - Integer.parseInt(year.getAdapter().getItem(0)));

        month = (WheelView) findViewById(R.id.month);
        month.setAdapter(new NumericWheelAdapter(1, 12));// "%02d"
        // month.setLabel("月");
        month.setCyclic(true);
        month.setCurrentItem(Integer.parseInt(icurMonth) - 1);

        int daysOfMounth = getDaysOfMounth();
        day = (WheelView) findViewById(R.id.day);
        day.setAdapter(new NumericWheelAdapter(1, daysOfMounth));
        // day.setLabel("日");
        day.setCyclic(true);
        day.setCurrentItem(Integer.parseInt(icurDay) - 1);

        OnWheelScrollListener scrollListener = new OnWheelScrollListener()
        {
            public void onScrollingStarted(WheelView wheel)
            {
            }

            public void onScrollingFinished(WheelView wheel)
            {
                int daysOfMounth = getDaysOfMounth();
                day.setAdapter(new NumericWheelAdapter(1, daysOfMounth));
            }
        };

        year.addScrollingListener(scrollListener);
        month.addScrollingListener(scrollListener);
        // day.addScrollingListener(scrollListener);

    }

    private int getDaysOfMounth()
    {
        int mMonth = Integer.parseInt(month.getAdapter().getItem(month.getCurrentItem()));
        switch (mMonth)
        {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            case 2:
                int mYear = Integer.parseInt(year.getAdapter().getItem(year.getCurrentItem()));
                if (mYear % 4 == 0 && mYear % 100 != 0 || mYear % 400 == 0)
                {
                    return 29;
                }
                else
                {
                    return 28;
                }
        }
        return -1;
    }

    private void initValues()
    {

    }

    View.OnClickListener clickListener = new View.OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            switch (v.getId())
            {
                case R.id.btn_left:
                    dismiss();
                    break;
                case R.id.btn_right:
                    String mYear = year.getAdapter().getItem(year.getCurrentItem());
                    String mMonth = month.getAdapter().getItem(month.getCurrentItem());
                    String mDay = day.getAdapter().getItem(day.getCurrentItem());
                    if (mDay == null || mDay.length() == 0)
                    {
                        mDay = "1";
                    }
                    if (Integer.parseInt(mMonth) < 10)
                    {
                        mMonth = "0" + mMonth;
                    }
                    if (Integer.parseInt(mDay) < 10)
                    {
                        mDay = "0" + mDay;
                    }
                    if (onOKClickListener != null)
                    {
                        onOKClickListener.onOKClick(mYear, mMonth, mDay);
                    }
                    dismiss();
                    break;

                default:
                    break;
            }
        }

    };

    private OnOKClickListener onOKClickListener;

    public interface OnOKClickListener
    {
        public void onOKClick(String year, String month, String date);
    }

    public void setOnOKClickListener(OnOKClickListener onOKClickListener)
    {
        this.onOKClickListener = onOKClickListener;
    }
}

  


DatePickerDialog的布局文件:
    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:gravity="center"
    android:background="@drawable/bg_picker_dialog"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:padding="8dp" 
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:layout_weight="1" 
            android:gravity="center_horizontal"
            >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:scaleType="fitCenter"
                />

            <com.widget.wheel.WheelView
                android:id="@+id/year"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginBottom="10dip"
                android:layout_marginTop="10dip"
                android:layout_weight="1" 
                />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:scaleType="fitCenter"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:layout_weight="1" 
            android:gravity="center_horizontal"
            >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:scaleType="fitCenter"
                />

            <com.widget.wheel.WheelView
                android:id="@+id/month"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginBottom="8dip"
                android:layout_marginTop="8dip"
                android:layout_weight="1" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:scaleType="fitCenter"
                />
        </LinearLayout>
        
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:layout_weight="1" 
            android:gravity="center_horizontal"
            >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:scaleType="fitCenter"
                />

            <com.widget.wheel.WheelView
                android:id="@+id/day"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginBottom="8dip"
                android:layout_marginTop="8dip"
                android:layout_weight="1" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:scaleType="fitCenter"
                />
        </LinearLayout>
        
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:orientation="horizontal"
        android:background="@drawable/line_top_with_blue"
        >

        <Button
            android:id="@+id/btn_left"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:paddingBottom="8dip"
            android:paddingTop="8dip"
            android:text="@string/cancel"
            android:textColor="@android:color/black"
            android:textSize="@dimen/font_big" 
            android:background="@drawable/bg_btn_trans_blue_with_no_corner"
            />


        <View 
            android:layout_width="@dimen/line_width"
            android:layout_height="match_parent"
            android:background="@color/primary"
            />
        
        <Button
            android:id="@+id/btn_right"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:paddingBottom="8dip"
            android:paddingTop="8dip"
            android:text="@string/confirm"
            android:textColor="@android:color/black"
            android:textSize="@dimen/font_big" 
            android:background="@drawable/bg_btn_trans_blue_with_no_corner"
            />
    </LinearLayout>

</LinearLayout>

  


style:
    
<style name="Theme_Dialog_NoTitle" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

  



使用:
    
dialog = new DatePickerDialog(context, R.style.Theme_Dialog, btn_startDate.getText().toString().trim());
			dialog.setOnOKClickListener(new DatePickerDialog.OnOKClickListener()
            {

                @Override
                public void onOKClick(String year, String month, String date)
                {
                    // TODO Auto-generated method stub
                    //dosomething
                    //btn_startDate.setText(year + "-" + month + "-" + date);
                   
                }
            });
            dialog.show();

  


WheelView類見附件,直接加入到你的工程中即可

基于WheelView自定義的DatePickerDialog


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本无码少妇波多野结衣 | 精品久久久久一区二区国产 | 操出白浆在线观看 | 日韩美女福利视频 | 香港三级日本三级a视频 | 欧美日韩精品一区二区在线线 | 国产亚洲精品2021自在线 | 这里只有精品999 | 久草青青草 | 亚洲成av人片在线观看 | 日韩三极 | 久色视频在线观看 | 毛片成人网 | 偷拍自拍成人 | 日韩成人免费视频 | 极品嫩模私拍后被潜在线观看 | 久久91久久91精品免费观看 | 久久精品伊人网 | 久草免费福利资源站 | av在线浏览 | 亚欧在线一线 | 亚洲一区二区三区在线看 | 精品自拍视频 | 亚洲精品高清视频 | 日韩高清不卡 | 一区二区三区亚洲 | av看片网站 | 日韩一区二区视频 | 国产精品成人自拍 | 国产色情A片国语露对白 | 亚洲国产中文字幕在线观看 | 久草视频手机在线 | 免费污的网站 | a级在线观看免费 | 亚洲呦呦系列视频 | 亚洲 欧美 日韩 在线 | 日韩视频在线免费观看 | 日韩www| 日韩精品资源 | 天天干网| 日韩欧美在线观看视频一区二区 |