add functionality to normal backspace
New to programming, new to Android. have figured out dynamic view creation,deletion and id assignment, but.....
i need to know how to have the backspace work n开发者_JS百科ormally unless there is no text in the current edittext, in which case the current view (edittext) would be deleted and the cursor and focus would jump to the edittext before it.
Any help would be very appreciated. thanks, Chris
You need to use an onKeyListener for your EditText field:
EditText et = new EditText();
et.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case 82:
case 84:
return false; // menu and search buttons
case 66:
return true; // enter button
case 4:
case 67:
return false; // back and delete buttons
default:
return true;
}
};
});
Hope you were looking for something along these lines.
To put focus to another edit text use:
EditText et = new EditText();
et.requestFocus();
精彩评论