Vamsi Vamsi - 1 month ago 9
Android Question

Move focus from one Edit text box to another

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?

Answer

Well, I found the answer: we can simply call input2.requestFocus(); to change the focus.

Comments