1
Hello folks I am developing an application in which the user must enter a quantity and the unit value and the application calculates the total payable. But if you delete all the value that is in the fields the program aborts. How can I fix this?
Incluprodutoactivity.java
public class IncluirProdutoActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_incluir_produto);
final EditText quantidade = (EditText) findViewById(R.id.quantidade);
final EditText precoUnitario = (EditText) findViewById(R.id.preco_unitario);
final EditText valorTotal = (EditText) findViewById(R.id.valor_total);
quantidade.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
Float preco = Float.valueOf(precoUnitario.getText().toString());
Float q = Float.valueOf(s.toString());
Float total = q * preco;
valorTotal.setText(total.toString());
}
});
}
}