Created
February 15, 2020 07:31
-
-
Save PamilerinId/108a056860bb722a7982296161a80b8e to your computer and use it in GitHub Desktop.
calculate amount on quantity input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remove this line:
amountEditText.addTextChangedListener {
amountChanged(it.toString())
}