Android: EditText Validation with TextWatcher and .setError()

前端 未结 2 1484
情话喂你
情话喂你 2020-12-10 23:39

i have implemented a simple validation for an TextEdit, using this code:

    title = (EditText) findViewById(R.id.title);
    title.addTextChangedListener(ne         


        
2条回答
  •  隐瞒了意图╮
    2020-12-11 00:01

    You should be able to also override the onKeyUp method (http://developer.android.com/reference/android/view/KeyEvent.Callback.html). In there, check to see if the key pressed was KeyEvent.KEYCODE_DEL, then also check to see if the text in the EditText is empty. If it is, throw your error.

提交回复
热议问题