how to calculate on real time?
I want to create calculator which have开发者_如何学编程 2 edit text name input1 and input2 and have spinner which show the operand so I try
input1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
calculate();
return false;
}
});
but it's not on time , I have to press back space 1 time in any edittext to calculate it
I think the problem is "onKey" function
Any ideas?
It sounds like you want the calculations to happen on the fly, and you don't have need for a button.
If that is true, you could attach a TextWatcher to each EditText via the addTextChangedListener(TextWatcher) method. Whenever you receive an event from it, you can call calculate(). In this instance you would probably also want to attach an AdapterView.OnItemSelectedListener to your Spinner.
If you ARE using a button to do your calculations, you would simply have a button, give it an OnClickListener which would call your calculate method.
精彩评论