Search code examples
androidandroid-edittextspinner

Android UI update notification


I am having 3 Edittexts and 3 spinner in my view, Whenever there is change in any edittext text value or change in any spinner selection I have to make service cal , How do I get notify like there is change in edittext or spinner selection?


Solution

  • You need to add listeners to the EditTexts and Spinners.

    For the EditTexts try this:

    editText1.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            // your code here
        }
    
        @Override    
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // your code here
        }
    
        @Override    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // your code here
        }
    });
    

    And for the Spinners try this:

    spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            // your code here
        }
    
        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
            // your code here
        }
    }