Fix errors when amount is null

This commit is contained in:
Reimar 2025-05-16 11:15:42 +02:00
parent 59683ea176
commit 47938544ef
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
2 changed files with 3 additions and 2 deletions

View File

@ -28,7 +28,7 @@ class ShoppingItemAdapter(context: Context, items: ArrayList<ShoppingListItem>)
val nameView = view.findViewById<TextView>(R.id.name)
val textViews = listOf(amountView, unitView, nameView)
amountView.text = DecimalFormat("#.##").format(item.amount)
amountView.text = if (item.amount != null) DecimalFormat("#.##").format(item.amount) else ""
unitView.text = item.unit
nameView.text = item.name

View File

@ -192,7 +192,8 @@ class ShoppingListFragment : Fragment() {
.setPositiveButton(R.string.add_label) { dialog, id ->
val dialog = dialog as AlertDialog
val amount = view.findViewById<EditText>(R.id.amount).text.toString().toDouble()
val amountStr = view.findViewById<EditText>(R.id.amount).text.toString()
val amount = if (amountStr.isEmpty()) null else amountStr.toDouble()
val unit = view.findViewById<Spinner>(R.id.unit_selector).selectedItem.toString()
.ifEmpty { null }
val name = view.findViewById<EditText>(R.id.name).text.toString()