监听EditText

0、得到焦点的时候,作一些处理

public class AbcActivity extends Activity implements OnFocusChangeListener{
  
@Override
    public void onFocusChange(View v, boolean hasFocus) {
        switch (v.getId()) {
        case R.id.edtKeys:
            setLayoutVisible(0);
            break;

        default:
            break;
        }
    }

}
 

1、点击文本框,输入值后,显示一个X的清空的按钮

2、点击清空按钮后,EditText清空,并且隐一个X的清空的按钮

 

edtKeys.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                if(s.toString().equals("")){
                    btn_delSearchKey.setVisibility(View.GONE);
                }else{
                    btn_delSearchKey.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                
            }

            @Override
            public void afterTextChanged(Editable s) {
                
            }
        });
        edtKeys.setOnFocusChangeListener(this);

 

posted @ 2015-10-04 10:39  jiduoduo  阅读(187)  评论(0编辑  收藏  举报