监听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);
道法自然