I wanted a numeric keypad that had a go or done button that closed and executed a calculation class. Thanks to a tip from commonware on where to start I got this working bea
I was using an EditText with inputType="number" and solved the problem by modifying Asha's solution:
private TextView.OnEditorActionListener numberEnterListener = new TextView.OnEditorActionListener(){
public boolean onEditorAction(TextView tv, int actionId, KeyEvent event){
if(actionId == EditorInfo.IME_ACTION_DONE
|| actionId == EditorInfo.IME_NULL
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
tv.clearFocus();
//Stupid keyboard needs to be closed as well
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);
return true;
} else {
return false;
}
}
};
The focus was removed in order to stop showing the number pad. The imm was required because a soft keyboard was still present even after clearing focus.