+ Reply to Thread
Results 1 to 2 of 2

Thread: Watch text changing and restrain change

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    31

    Watch text changing and restrain change

    I have a EditText where I enter a number.
    What I want is to deny this number to have more than "x" number of decimals.
    Any idea how can i do that ? because i used TextWatcher but didn`t work.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    You can add a class variable which stores the last previous value of the edit text
    Please try this solution :
    Code:
     precioProducto.addTextChangedListener(new TextWatcher(){
                        public void afterTextChanged(Editable s) {
    
                        }
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                        }
                        public void onTextChanged(CharSequence s, int start, int before, int count) {                      
    
                            String[] numeroDecimal = s.toString().split(",");
                            if(numeroDecimal[1].length()>=3){
                              precioProducto.setText(lastVal);
                            }
                            lastVal=s.toString();
                        }
                    });

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts