Question

TextWatcher

TextWatcher listener = new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(editYear.getText().toString().equals("") && editCapacity.getText().toString().equals("")){

                    calc.setEnabled(true);

                }
                    calc.setEnabled(true);
            }
        };

ButtonProp

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Calc"
    android:id="@+id/calc"
    android:layout_below="@+id/editCapacity"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:enabled="false"


    />

I'm a begginer ,this is my first app, basicly i need the text watcher to see if the text is mising in the edit text 1 and 2 ,to set the button enable function to false if they are blank,my textwatch evaluates only one condition,but i need them both Please Help

Was it helpful?

Solution

Replace the below code in afterTextChanged.

public void afterTextChanged(Editable s) {
        if(edtitYear.getText().toString().length()==0||edtitCapacity.getText().toString().length()==0){
            calc.setEnabled(false);
        }else{
            calc.setEnabled(true);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top