vendredi 16 février 2018

Android Studio show TextView text dependant on answer

I am very new to this sort of thing and am trying to teach myself but have gotten stuck here. I am writing an app which will calculate the size battery required. The calculator side of things i have done and it is working however i want to add a feature that when the answer is displayed, it will tell you what part number you need for the battery required. I have tried to work this out myself and failed miserably so i am hoping someone may be able to point me in the right direction

The answer from the battery calculator shows in ahresult. what i want is battreq to show the part number required for the correct size battery. so for example, if the calculator showed that a 2.43Ah battery was required, battreq would show "A 3.2ah battery is required" as that is the next size available.

ahresult = (TextView) findViewById(R.id.ahresult);

        battreq.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) {
                Integer.parseInt(ahresult.getText().toString());
                if (ahresult.equals(>= "0.00" && <=  "1.20")){
                    battreq.setText("A 1.2Ah battery is required");
                }
                else if (ahresult.equals (>= "1.21 && <= 2.10")){
                    battreq.setText("A 2.1Ah battery is required");
                }
                else if (ahresult.equals (>= "2.11 && <= 3.20")){
                    battreq.setText("A 3.2Ah battery is required");
                }
              // so on and so on with different battery sizes
            }

Here is my (poor) effort at having a go but i am getting illegal start of expression.

Could someone guide me in the right direction please?

Aucun commentaire:

Enregistrer un commentaire