首页 > 其他分享 >6.17 4

6.17 4

时间:2024-06-17 23:56:57浏览次数:26  
标签:String int 6.17 dialog time import android

package com.zhen.accountbook.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import androidx.annotation.NonNull;
import com.zhen.accountbook.R;

//在记录页面弹出时间对话框
public class SelectTimeDialog extends Dialog implements View.OnClickListener {
    EditText hourEt, minEt;
    DatePicker datePicker;
    Button ensureBtn, cancelBtn;

    public interface OnEnsureListener {
        public void onEnsure(String time, int year, int month, int day);
    }

    public void setOnEnsureListener(OnEnsureListener onEnsureListener) {
        this.onEnsureListener = onEnsureListener;
    }

    OnEnsureListener onEnsureListener;

    public SelectTimeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_calendar);
        hourEt = findViewById(R.id.dialog_time_et_hour);
        minEt = findViewById(R.id.dialog_time_et_min);
        datePicker = findViewById(R.id.dialog_time_dp);
        ensureBtn = findViewById(R.id.dialog_time_btn_ensure);
        cancelBtn = findViewById(R.id.dialog_time_btn_cancel);
        ensureBtn.setOnClickListener(this);
        cancelBtn.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.dialog_time_btn_ensure) {
            if (onEnsureListener != null) {
                int year = datePicker.getYear();
                int month = datePicker.getMonth() + 1;
                int day = datePicker.getDayOfMonth();
                String monthStr = String.valueOf(month);
                if (month < 10) {
                    monthStr = "0" + month;
                }
                String dayStr = String.valueOf(day);
                if (day < 10) {
                    dayStr = "0" + day;
                }
                String hourStr=hourEt.getText().toString();
                String minStr=minEt.getText().toString();
                int hour=0;
                if (!TextUtils.isEmpty(hourStr)) {
                    hour=Integer.parseInt(hourStr);
                    hour=hour%24;
                }
                int min=0;
                if (!TextUtils.isEmpty(minStr)) {
                    min=Integer.parseInt(minStr);
                    min=min%60;
                }
                hourStr=String.valueOf(hour);
                minStr=String.valueOf(min);
                if (hour<10) {
                    hourStr="0"+hourStr;
                }
                if (min<10) {
                    minStr="0"+minStr;
                }
                String time=year+"-"+monthStr+"-"+dayStr+" "+hourStr+":"+minStr;
                onEnsureListener.onEnsure(time,year,month,day);
            }
        } else if (view.getId() == R.id.dialog_time_btn_cancel) {
            cancel();
        }
    }
    //隐藏 DatePicker头布局
//    private void hideDatePickerHeader(){
//        ViewGroup rootView= (ViewGroup) datePicker.getChildAt(0);
//   if (rootView==null){
//       return ;
//   }View headView=rootView.getChildAt(0);
//   if(headView==null){
//       return ;
//   }
//    }
}

 

标签:String,int,6.17,dialog,time,import,android
From: https://www.cnblogs.com/zzqq1314/p/18253468

相关文章

  • 6.17 3
    packagecom.zhen.accountbook;importandroid.os.Bundle;importandroid.view.View;importandroidx.appcompat.app.AppCompatActivity;importandroidx.fragment.app.Fragment;importandroidx.viewpager.widget.ViewPager;importcom.google.android.material.tabs.......
  • 6.17 2
    记账本APPpackagecom.zhen.accountbook;importandroid.content.Context;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.text.method.HideReturnsTransformationMethod;importandroid.text.method.PasswordTransformationMe......
  • 6.17 5
    自定义软键盘packagecom.zhen.accountbook.utils;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.text.Editable;importandroid.text.InputType;importandroid.view.View;importandroid.widget.EditTex......
  • 6.17 7
    packagecom.zhen.accountbook.frag_record;importandroid.inputmethodservice.KeyboardView;importandroid.os.Bundle;importandroid.text.TextUtils;importandroid.widget.*;importandroidx.annotation.Nullable;importandroidx.fragment.app.Fragment;import......
  • 6.17 6
    packagecom.zhen.accountbook.utils;importandroid.app.Dialog;importandroid.content.Context;importandroid.os.Bundle;importandroid.text.TextUtils;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid......
  • 6.17 8
    packagecom.zhen.accountbook.adapter;importandroid.content.Context;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.BaseAdapter;importandroid.widget.ImageView;importandroid.widget.T......
  • 6.17 10
    <?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layou......
  • 6.17 9
    <?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="wrap_con......
  • 2024.6.17鲜花/错误的号码
    XY星的星际新闻报一直不太畅销,所以报纸上会有一些广告,毕竟星际新闻局的非机器人员工也得吃饭。有一则广告是这样的:【数据删除】研学基地位于【数据删除】,该研学基地致力于让学生体验一个幻想纪前的生活并培养学生不借助现代高科技的群居生活能力。该研学基地将于幻想历元年六......
  • 6.17 学习心得
    这本书讲述了几十年前软件专案管理问题与经验,作者将大型系统开发比作一个焦油坑,我原本以为软件开发还是比较容易的,有了新想法,就会有新的软件产品出现,但是却不知道项目不能满足目标、进度、预算的要求,就不能成为一个好项目。程序,通过不同的途径转变成不同的产物,使之变得更有用,成本......