Basically I have created a Blackjack app that uses several methods that get called and pass a long the information that is needed (about cards and actions). I have 2 buttons displayed on screen that are click able (hit and stand). Now I have a method called player turn… and this is when I (through static ints) have if a button is selected, things will happen. However I did this with an infinite while loop thinking it will just keep checking to see if a button is pressed and then only do action when a button is pressed. This isn’t working as my screen is not refreshing after each textview or imageview change thus as soon as I hit start game the game appears to “freeze” (being due to the method never ending) and I am therefore unable to click said buttons. Is there a way to call something similar to keyboard listener in java (Which pauses activity and waits for user input), in android? If not, what would you suggest the workaround be? Lastly (though not as currently important) how would I properly refresh everything after each change (I believe I need to use invalidate.. though I’m not sure what to have before invalidate so it refreshes the whole thing)? Thanks a bunch in advance.
Basically I have created a Blackjack app that uses several methods that get called
Share
Android will run an event loop for you – so you don’t have to loop around waiting for input yourself.
You can hook into the loop in a number of ways. From 1.6 onwards the easiest way to do this is to specify the hook in your XML, e.g:
<Button android:onClick=”myClickHandler” />
Alternatively you can do this in code by calling setOnClickListener.
Take a look at http://android-developers.blogspot.com/2009/10/ui-framework-changes-in-android-16.html for some examples (read the section headed “Easier click listeners”)
If you can invalidate on your view then the Android event loop will take care of re-drawing the screen, including any layout changes. If you have custom View’s their onDraw() will be called as appropriate.
Hope this helps.