tags:

views:

312

answers:

1

Hi, I am writing a simple calculator application(using absolute layout with 3 edit boxes and some buttons), which has two inputtext boxes and a output box.

input1 = (EditText) findViewById(R.id.input1);
input2 = (EditText) findViewById(R.id.input2);

now once user enters some numerics into input1 and presses '+', now i want to shift the focus from input1 to input2. How can i do that?

I tried the below code on keypress of '+'

onClick(View arg0){
                operator.setText("+");
                //Move focus from input1 to input2
                input1.clearFocus();
                input2.setNextFocusDownId(input2.getId());
        }

but this is not working.. can you please help me on this?

A: 

[By the way, you want to avoid using AbsoluteLayout - it's deprecated, and may be removed.]

Instead of using onClick, you want the action to happen in a KeyListener's onKeyDown method.

See: setKeyListener

Then you can examine the KeyEvent's key with

KeyEvent.getAction() == KeyEvent.KEYCODE_PLUS

Klondike