91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

datepicterDialog和timepicterDialog取消按鈕

發布時間:2020-08-06 11:39:43 來源:網絡 閱讀:868 作者:lg491733638 欄目:移動開發

這是日期彈出框的第一種彈出方式:分開彈出datepicterdialog和timepicterdialog

 

final DatePickerDialog datePickerDialog = new DatePickerDialog(
       TableChart.this, null, mYear, mMonth,
       mDay);
     datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE,
       "完成", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface arg0,
          int arg1) {
         DateTimeUtils.showDatePositive(datePickerDialog,starttime);
        }
       });
     datePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
       "取消", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface arg0,
          int arg1) {
         DateTimeUtils.showDateNegative(starttime);
        }
       });
     datePickerDialog.setCanceledOnTouchOutside(false);
     datePickerDialog.show();
 
public static void showDatePositive(DatePickerDialog datePickerDialog,
   EditText yearEdit) {
  DatePicker datePicker = datePickerDialog.getDatePicker();//獲取DatePicter對象
  int year = datePicker.getYear();
  int month = datePicker.getMonth() + 1;
  int day = datePicker.getDayOfMonth();
  yearEdit.setText(year+"-"month+"-"+day);
  yearEdit.clearFocus();
  }
public static void showDateNegative(EditText yearEdit) {
  yearEdit.clearFocus();
  }
由于timepicterDialog無法獲取到timepicter,所以重寫:MyTimePickerDialog.java
package com.rts.dzdc.utils;
import com.rts.dzdc.activity.R;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
/**
* 基本上把源碼套用了一下
* @author Lee
*
*/
public class MyTimePickerDialog extends AlertDialog
        implements OnClickListener, OnTimeChangedListener {
public interface OnTimeSetListener {
        void onTimeSet(TimePicker view, int hourOfDay, int minute);
    }
    private static final String HOUR = "hour";
    private static final String MINUTE = "minute";
    private static final String IS_24_HOUR = "is24hour";
    private final TimePicker mTimePicker;
    private final OnTimeSetListener mCallback;
    int mInitialHourOfDay;
    int mInitialMinute;
    boolean mIs24HourView;
  
    public MyTimePickerDialog(Context context,
            OnTimeSetListener callBack,
            int hourOfDay, int minute, boolean is24HourView) {
        this(context, 0, callBack, hourOfDay, minute, is24HourView);
    }
  
    public MyTimePickerDialog(Context context,
            int theme,
            OnTimeSetListener callBack,
            int hourOfDay, int minute, boolean is24HourView) {
        super(context, theme);
        mCallback = callBack;
        mInitialHourOfDay = hourOfDay;
        mInitialMinute = minute;
        mIs24HourView = is24HourView;
        setIcon(0);
        setTitle("設置時間");
        Context themeContext = getContext();
        setButton(BUTTON_POSITIVE, "完成", this);
        LayoutInflater inflater =
                (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.time_picker_dialog, null);
        setView(view);
        mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);
        // initialize state
        mTimePicker.setIs24HourView(mIs24HourView);
        mTimePicker.setCurrentHour(mInitialHourOfDay);
        mTimePicker.setCurrentMinute(mInitialMinute);
        mTimePicker.setOnTimeChangedListener(this);
    }
    public void onClick(DialogInterface dialog, int which) {
        tryNotifyTimeSet();
    }
    public void updateTime(int hourOfDay, int minutOfHour) {
        mTimePicker.setCurrentHour(hourOfDay);
        mTimePicker.setCurrentMinute(minutOfHour);
    }
    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
        /* do nothing */
    }
    private void tryNotifyTimeSet() {
        if (mCallback != null) {
            mTimePicker.clearFocus();
            mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(),
                    mTimePicker.getCurrentMinute());
        }
    }
    @Override
    protected void onStop() {
        tryNotifyTimeSet();
        super.onStop();
    }
    @Override
    public Bundle onSaveInstanceState() {
        Bundle state = super.onSaveInstanceState();
        state.putInt(HOUR, mTimePicker.getCurrentHour());
        state.putInt(MINUTE, mTimePicker.getCurrentMinute());
        state.putBoolean(IS_24_HOUR, mTimePicker.is24HourView());
        return state;
    }
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        int hour = savedInstanceState.getInt(HOUR);
        int minute = savedInstanceState.getInt(MINUTE);
        mTimePicker.setIs24HourView(savedInstanceState.getBoolean(IS_24_HOUR));
        mTimePicker.setCurrentHour(hour);
        mTimePicker.setCurrentMinute(minute);
    }
   
    /**
     * 自己加的獲取TimePicker方法
     * @return
     */
    public TimePicker getTimePicker()
    {
     return mTimePicker;
    }
}
使用方法:
final MyTimePickerDialog timePickerDialog = new MyTimePickerDialog(
         TableSlideZaiHaiActivity.this, null,
         mhour, mmintue, true);
       timePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE,
         "完成", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface arg0,
            int arg1) {
           DateTimeUtils.showTimePositive(timePickerDialog,hour);
          }
         });
       timePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
         "取消", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface arg0,
            int arg1) {
           DateTimeUtils.showTimeNegative(slidedown_huadongtimehour);
          }
         });
       timePickerDialog.setCanceledOnTouchOutside(false);
       timePickerDialog.show();
      
       public static void showTimePositive(MyTimePickerDialog timePickerDialog,EditText hourEdit) {
  TimePicker timePicker = timePickerDialog.getTimePicker();
  int hour = timePicker.getCurrentHour();
  int mintue = timePicker.getCurrentMinute();
  hourEdit.setText(hour+":"+mintue);
   hourEdit.clearFocus();
   }
public static void showTimeNegative(EditText hourEdit, EditText ) {
  hourEdit.clearFocus();
   }
  

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

武邑县| 宜章县| 甘孜县| 东源县| 石嘴山市| 辽阳市| 册亨县| 三江| 门源| 云安县| 芦山县| 荃湾区| 法库县| 云霄县| 沅陵县| 永清县| 东乡| 东方市| 建湖县| 饶阳县| 辰溪县| 乾安县| 丹巴县| 肥乡县| 昌邑市| 泗阳县| 嵩明县| 怀宁县| 和田市| 扎赉特旗| 成武县| 饶平县| 砚山县| 汉中市| 保德县| 济南市| 兖州市| 始兴县| 舞阳县| 商都县| 西盟|