12 Mar 2011, 07:58
Generic-user-small

Herman (2 posts)

Hello, I have a question on page 85 regarding SetListeners() in Keypad.java. We use a for loop to set listeners for all keypad values and then we do the same for keypad. My question is, does setting listeners on keys[] alone suffice? Do we really need to set listener for keypad and call returnResult with a zero?

Thanks!

14 Mar 2011, 08:37
Generic-user-small

Anthony Shaw (115 posts)

The short answer is ‘yes’. The explanation in the paragraph after the code says why, to paraphrase clicking a button with a number on it returns the number, clicking a blank tile returns zero to indicate there is no number.

15 Mar 2011, 03:20
Generic-user-small

Herman (2 posts)

Thanks for reply. But since invalid buttons views are already set invisible, could we simply not register onclickListeners to those buttons that are set invisible and simply do nothing when clicked? Other words, no events would be raised when they are tapped on/clicked upon?

17 Mar 2011, 00:26
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

I did it that way so if you clicked anywhere in the Keypad view where there wasn’t a number, it would erase the current tile. It does this whether you clicked on the spot an invisible number would normally have been, or in the padding between or around the numbers, or off to the side, as long as you’re still somewhere in the Keypad view’s rectangle.

Another way to do it would have been to add a “Clear” button to the Keypad view.

  You must be logged in to comment