В Android я могу сделать так, чтобы пользователь мог щелкнуть за пределами режима редактирования, чтобы скрыть виртуальную клавиатуру.
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
View v = getCurrentFocus();
boolean ret = super.dispatchTouchEvent(event);
if (v instanceof EditText) {
View w = getCurrentFocus();
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = event.getRawX() + w.getLeft() - scrcoords[0];
float y = event.getRawY() + w.getTop() - scrcoords[1];
if (event.getAction() == MotionEvent.ACTION_UP
&& (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w
.getBottom())) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus()
.getWindowToken(), 0);
}
}
return ret;
}
А в ежевике? Я хочу баллотироваться только за VirtualKeyboard.isSupported()
.
Обновить
public class Custom_EditField extends EditField {
private int width, row, color;
private MainScreen mainscreen;
Custom_EditField(long style, int width, int row, MainScreen mainscreen) {
super(style);
this.width = width;
this.row = row;
this.mainscreen = mainscreen;
}
public int getPreferredHeight() {
return Font.getDefault().getHeight() * row;
}
public int getPreferredWidth() {
return width;
}
protected void onFocus(int direction) {
if (VirtualKeyboard.isSupported())
mainscreen.getVirtualKeyboard().setVisibility(
VirtualKeyboard.SHOW_FORCE);
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
if (VirtualKeyboard.isSupported())
mainscreen.getVirtualKeyboard().setVisibility(
VirtualKeyboard.HIDE_FORCE);
invalidate();
super.onUnfocus();
}
public boolean isFocusable() {
return true;
}
protected void layout(int maxWidth, int maxHeight) {
super.layout(maxWidth,
Math.min(maxHeight, Font.getDefault().getHeight() * row));
super.setExtent(maxWidth,
Math.min(maxHeight, Font.getDefault().getHeight() * row));
}
protected void paint(Graphics graphics) {
int rectHeight = getPreferredHeight();
int rectWidth = getPreferredWidth();
try {
color = Color.BLACK;
graphics.setColor(color);
graphics.drawRect(0, 0, rectWidth, rectHeight);
super.paint(graphics);
} finally {
graphics.setColor(color);
}
}
}
Это поле редактирования скроет клавиатуру, если вы нажмете на другое поле, но не на любую точку.
EditField
. Можете ли вы опубликовать часть кода, показывающего, как создается вашEditField
? это помещено вVerticalFieldManager
? пользовательский подклассManager
? - person Nate   schedule 30.07.2012EditField
фокус теряется. Переопределение методаonUnfocus
дляEditField
может быть полезным. НоEditField
не потеряет фокус, если коснуться нефокусируемого элемента. - person Rupak   schedule 30.07.2012touchEvent()
вManager
, содержащем вашCustom_EditField
, вместо переопределенияunFocus()
, что не совсем работает. - person Nate   schedule 30.07.2012