开发者

add functionality to normal backspace

开发者 https://www.devze.com 2023-03-04 13:37 出处:网络
New to programming, new to Android. have figured out dynamic view creation,deletion and id assignment, but.....

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号