android edittext onchange listener

前端 未结 9 2212
长情又很酷
长情又很酷 2020-11-27 13:28

I know a little bit about TextWatcher but that fires on every character you enter. I want a listener that fires whenever the user finishes editing. Is it possib

9条回答
  •  不知归路
    2020-11-27 13:35

    The Watcher method fires on every character input. So, I built this code based on onFocusChange method:

    public static boolean comS(String s1,String s2){
        if (s1.length()==s2.length()){
            int l=s1.length();
            for (int i=0;i

    To using it, just call like this:

    onChange(YourEditText, new Runnable(){public void run(){
        // V  V    YOUR WORK HERE
    
        }}
    );
    

    You can ignore the comS function by replace the !comS(dat.s,""+EdTe.getText()) with !equal function. However the equal function itself some time work not correctly in run time.

    The onChange listener will remember old data of EditText when user focus typing, and then compare the new data when user lose focus or jump to other input. If comparing old String not same new String, it fires the work.

    If you only have 1 EditText, then u will need to make a ClearFocus function by making an Ultimate Secret Transparent Micro EditText

提交回复
热议问题