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 beautifully on the emulator. Then I came to load it on to my HTC desire for testing and it doesn't work at all. I'm sure it must be because of HTC sense having it's own ime but there must surely be a way to make this work on HTC phones? Anyone else managed to get around this issue?
I can replicate what I think you are seeing on the HTC Incredible.
Not all soft keyboards will support the IME action button. Some, like the Graffiti soft "keyboard", may have no buttons at all, let alone an IME action button. Even the Compatibility Definition Document says nothing about requiring such an action button for the keyboards supplied with a device.
Hence, you should not rely on the IME action button. If it is there, users can use it. However, always have some other means of accomplishing whatever your goal is.
ScrollView
so the user can scroll down, even with the soft keyboard exposed, to get to the calculate button. Lot of possibilities here, just depends on your particular GUI design. –
Sirreverence I am detecting whether the DONE / GO / RETURN button has been pressed using an onEditorActionListener, but checking for IME options and KeyEvents to cover HTC keyboards as well as any keyboards that accept IME options.
(This code works for HTC Incredible keyboards as well any keyboard that has IME options)
EditText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event){
if(actionId == EditorInfo.IME_ACTION_DONE
|| actionId == EditorInfo.IME_NULL
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
//Do something in here
return true;
} else {
return false;
}
}
});
if(event.getAction() == KeyEvent.ACTION_UP)
to prevent more then one call –
Dolor 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.
© 2022 - 2024 — McMap. All rights reserved.