|
|
@@ -4,7 +4,6 @@ import android.app.AlertDialog
|
|
|
import android.content.Context
|
|
|
import android.view.View
|
|
|
import android.widget.NumberPicker
|
|
|
-import android.widget.TextView
|
|
|
import com.google.android.material.button.MaterialButton
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
import com.google.android.material.textfield.TextInputEditText
|
|
|
@@ -17,7 +16,6 @@ class NumberPickerDialog(context: Context) {
|
|
|
private var numberPicker: NumberPicker? = null
|
|
|
private var editText: TextInputEditText? = null
|
|
|
private var inputLayout: TextInputLayout? = null
|
|
|
- private var tvRange: TextView? = null
|
|
|
private var maxValue: Int? = null
|
|
|
private var minValue: Int? = null
|
|
|
private var value: Int? = null
|
|
|
@@ -63,7 +61,6 @@ class NumberPickerDialog(context: Context) {
|
|
|
numberPicker = dialog.findViewById(R.id.number_picker)
|
|
|
inputLayout = dialog.findViewById(R.id.til_input)
|
|
|
editText = dialog.findViewById(R.id.et_input)
|
|
|
- tvRange = dialog.findViewById(R.id.tv_range)
|
|
|
val btnSwitch = dialog.findViewById<MaterialButton>(R.id.btn_switch_input)
|
|
|
|
|
|
numberPicker?.let { np ->
|
|
|
@@ -71,20 +68,23 @@ class NumberPickerDialog(context: Context) {
|
|
|
maxValue?.let { np.maxValue = it }
|
|
|
value?.let { np.value = it }
|
|
|
}
|
|
|
- tvRange?.text = "输入范围: ${numberPicker?.minValue} - ${numberPicker?.maxValue}"
|
|
|
|
|
|
btnSwitch?.setOnClickListener {
|
|
|
useInputMode = !useInputMode
|
|
|
if (useInputMode) {
|
|
|
numberPicker?.visibility = View.GONE
|
|
|
inputLayout?.visibility = View.VISIBLE
|
|
|
- tvRange?.visibility = View.VISIBLE
|
|
|
+
|
|
|
+ val min = minValue ?: numberPicker?.minValue
|
|
|
+ val max = maxValue ?: numberPicker?.maxValue
|
|
|
+ inputLayout?.hint = "输入范围: $min - $max"
|
|
|
+
|
|
|
editText?.setText(numberPicker?.value?.toString() ?: value?.toString())
|
|
|
} else {
|
|
|
numberPicker?.visibility = View.VISIBLE
|
|
|
inputLayout?.visibility = View.GONE
|
|
|
- tvRange?.visibility = View.GONE
|
|
|
inputLayout?.error = null
|
|
|
+ inputLayout?.hint = null
|
|
|
}
|
|
|
}
|
|
|
|