mercredi 11 février 2015

[Q] empty fields crast my app topic






Hello everyone,

I have start my first app, with this app, can you count your small change. And It works fine.
But, the fields must have a number, otherwise will my app cras.

Is there a solution to fix this? I mean if the user no number set on a row, that the app see this as a zero?

This looks my app:



this is the code what i use, it is maby not perfect but I am a beginner.


Code:


            Button btn_optellen = (Button) findViewById(R.id.btn_optellen);
           
            btn_optellen.setOnClickListener(new OnClickListener() {
                       
                        @Override
                        public void onClick(View v) {
                       
                                double een = Double.valueOf(txt_001.getText().toString());
                                double twee = Double.valueOf(txt_002.getText().toString());

                                double total_een = een * 0.01 ;
                                double total_twee = twee * 0.02 ;

                              double totaal = total_een + total_twee;

                                tt_001.setText(String.format("= €%.2f", total_een ));
                                tt_002.setText(String.format("= €%.2f", total_twee ));

                              tt_totaal.setText(String.format("= €%.2f", totaal));








Aucun commentaire:

Enregistrer un commentaire