gzu-liyujiang / AndroidPicker

安卓选择器类库,包括日期及时间选择器(可用于出生日期、营业时间等)、单项选择器(可用于性别、民族、职业、学历、星座等)、二三级联动选择器(可用于车牌号、基金定投日期等)、城市地址选择器(分省级、地市级及区县级)、数字选择器(可用于年龄、身高、体重、温度等)、日历选日期择器(可用于酒店及机票预定日期)、颜色选择器、文件及目录选择器、图片选择器等……WheelPicker/DatePicker/TimePicker/OptionPicker/NumberPicker/LinkagePicker/AddressPicker/CarPlatePicker/CalendarPicker/ColorPicker/FilePicker/ImagePicker etc.
Other
6.51k stars 1.47k forks source link

日历无法选择同一天 #325

Closed lileii closed 2 years ago

lileii commented 2 years ago

依赖:implementation 'com.github.gzu-liyujiang.AndroidPicker:CalendarPicker:4.1.0'

代码如下:

import android.os.Bundle import android.util.Log import android.widget.Toast import androidx.fragment.app.FragmentActivity import com.github.gzuliyujiang.calendarpicker.CalendarPicker import com.lihuowan.nftplayer.databinding.ActivityLaunchBinding import java.text.DateFormat import java.util.*

class LaunchActivity :FragmentActivity(){

companion object{
    const val TAG="LaunchActivity"
}

  var startTimeInMillis: Long =0L
  var endTimeInMillis: Long = 0L
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val binding = ActivityLaunchBinding.inflate(layoutInflater)
    setContentView(binding.root)
 binding.aaaa.setOnClickListener {
        var picker = CalendarPicker(this)
        var currentDate = Date(System.currentTimeMillis())

        if (startTimeInMillis == 0L && endTimeInMillis == 0L) {
            Log.e(TAG, "onCreate: ", )
            startTimeInMillis = currentDate.getTime() - 3 * android.text.format.DateUtils.DAY_IN_MILLIS;
            endTimeInMillis = currentDate.getTime() + 3 * android.text.format.DateUtils.DAY_IN_MILLIS;
        }
        picker.setSelectedDate(startTimeInMillis, endTimeInMillis);
        picker.setOnRangeDatePickListener { startDate, endDate ->
            startTimeInMillis = startDate.time
            endTimeInMillis = endDate.time
            Log.e(TAG, "initView: $startDate+$endDate")
            Toast.makeText(
                this,
                """
                ${DateFormat.getDateTimeInstance().format(startDate)}
                ${DateFormat.getDateTimeInstance().format(endDate)}
                """.trimIndent(),
                Toast.LENGTH_SHORT
            ).show()
        }
        picker.show()

    }
}

}

备注,仓库代码直接dowmload下来的是正常的,依赖导入包是异常的,希回复,不尽感谢!

lileii commented 2 years ago

sorry 把10打成0了