I created a custom view:
public class MyCustomView extends LinearLayout {...}
When user touch it, I show keyboard like this:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
requestFocus();
showKeyboard(true);
}
return super.onTouchEvent(event);
}
public void showKeyboard(boolean show) {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (show) {
imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);
} else {
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
}
But how can I show a number keyboard, which user can only input digits, just like this for EditText?
mEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);