focus on second edittext only if first is non-empty android

后端 未结 3 705
别跟我提以往
别跟我提以往 2021-01-13 14:10

Currently I have two edit-text,suppose I want to make validation for empty edittext check.What is better way for runtime validation.

My code is;

             


        
3条回答
  •  伪装坚强ぢ
    2021-01-13 14:57

        final EditText ev1 = (EditText) findViewById(R.id.editText1);
        final EditText ev2 = (EditText) findViewById(R.id.editText2);
    
        ev1.setOnFocusChangeListener(new OnFocusChangeListener() {      
            @Override
            public void onFocusChange(View rv, boolean hasFocus) {
                if(!hasFocus && ev1.getText().length()==0)
                {    
                      new Handler().postDelayed(new Runnable() {
    
                      @Override
                      public void run() {
                           ev2.clearFocus();
                       ev1.requestFocus();
    
                      }
                }, 100);
    
             }
          }
        });
    

提交回复
热议问题