Skip to content

Instantly share code, notes, and snippets.

@PamilerinId
Created February 15, 2020 07:31
Show Gist options
  • Save PamilerinId/108a056860bb722a7982296161a80b8e to your computer and use it in GitHub Desktop.
Save PamilerinId/108a056860bb722a7982296161a80b8e to your computer and use it in GitHub Desktop.
calculate amount on quantity input
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setupAppbar()
val symbol = intent.getStringExtra(SYMBOL_KEY) ?: throw IllegalArgumentException()
isSellForm = intent.getBooleanExtra(SELL_KEY, false)
buyStockButton.setText(if (isSellForm) R.string.action_sell_stock else R.string.action_buy_stock)
categoryStockViewModel.tags = symbol
radioButtonByText = indexRadioButtonChildren()
fetchContent()
amountRadioGroup.setOnCheckedChangeListener { group: RadioGroup?, checkedId: Int ->
onCheckedChange(group, checkedId)
}
amountEditText.addTextChangedListener {
amountChanged(it.toString())
}
buyStockButton.setBlockingOnClickListener {
buyStockClick()
}
viewModel.preOrderStockTransaction.observe(this, Observer { resource ->
preOrderStockResource(resource)
})
amountEditText.addTextChangedListener {
amountErrorTextView.text = ""
val amount = it.toString().toDoubleOrNull()
if (amount != null) {
quantityEditText.setText(String.format("%.4f", (amount / askPrice)))
} else {
quantityEditText.setText("")
}
}
quantityEditText.addTextChangedListener {
quantityErrorTextView.text = ""
//Hangs for some reason
val quantity = it.toString().toDoubleOrNull()
if (quantity != null) {
println((quantity * askPrice))
amountEditText.setText(String.format("%.4f", (quantity * askPrice)))
} else {
amountEditText.setText("")
}
}
priceEditText.addTextChangedListener {
priceErrorTextView.text = ""
}
orderTypeRadioGroup.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
orderTypeChanged(checkedId)
}
orderTypeChanged(R.id.marketOrderRadioButton)
}
@NezSpencer
Copy link

Remove this line:

amountEditText.addTextChangedListener {
amountChanged(it.toString())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment