我试图在一些文字后弹出键盘。即在满足某些条件后。如何在android中执行此操作。 即if(eT1的字符== et2的字符) eT1已经输入了,现在已经输入了et2。
我用过: eT2.addTextChangedListener(new TextWatcher(){
public void onTextChanged(CharSequence s, int start,int before, int count)
{
// TODO Auto-generated method stub
String oldPass = eT1.getText().toString(); if(!oldPass.contentEquals(e2.getText().toString()))
{
View view = this.getCurrentFocus();
if(view!= null){
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
}
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
答案 0 :(得分:1)
尝试这样的事情:
final EditText et1 = (EditText) findViewById(R.id.editText1);
final EditText et2 = (EditText) findViewById(R.id.editText2);
et1.setKeyListener(new KeyListener() {
public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) {
if(view.getText().equals(et2.getText()) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
return true;
}
return false;
}
}