Fix errors when amount is null
This commit is contained in:
parent
59683ea176
commit
47938544ef
@ -28,7 +28,7 @@ class ShoppingItemAdapter(context: Context, items: ArrayList<ShoppingListItem>)
|
|||||||
val nameView = view.findViewById<TextView>(R.id.name)
|
val nameView = view.findViewById<TextView>(R.id.name)
|
||||||
val textViews = listOf(amountView, unitView, nameView)
|
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
|
unitView.text = item.unit
|
||||||
nameView.text = item.name
|
nameView.text = item.name
|
||||||
|
|
||||||
|
@ -192,7 +192,8 @@ class ShoppingListFragment : Fragment() {
|
|||||||
.setPositiveButton(R.string.add_label) { dialog, id ->
|
.setPositiveButton(R.string.add_label) { dialog, id ->
|
||||||
val dialog = dialog as AlertDialog
|
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()
|
val unit = view.findViewById<Spinner>(R.id.unit_selector).selectedItem.toString()
|
||||||
.ifEmpty { null }
|
.ifEmpty { null }
|
||||||
val name = view.findViewById<EditText>(R.id.name).text.toString()
|
val name = view.findViewById<EditText>(R.id.name).text.toString()
|
||||||
|
Loading…
Reference in New Issue
Block a user