I'm a cobol structured programmer making the leap to Java OOP. I've written an ambitious card program where a user plays against 3 computer opponents. It's working but there is no delay between the 3 computer opponents and the user. I'd like it to seem like each opponent is playing a card individually. The user plays and each opponent updates two ImageViews
using a setImageDrawable
. The screen does not update until it reaches OnClickListener
for the user. I tried Thread.sleep
after each computer play which should leave the screen updatable, but while there is a delay the screen doesn't refresh until OnClickListener
. I don't have a LayoutInflater
because, well there's nothing to inflate - all 40 of my ImageViews
are crammed into the screen. I've tried a few emulators in Android Studio but they all have this affect. I've also tried invalidate on the fullscreen without success -- perhaps I should on the individual ImageViews
?
I'd post some of the code but it's rather lengthy and sloppy and I hope I've described the problem well enough. Any ideas how to fix or can you suggest some features in Java I can explore? My internet is a bit spotty so there may be a delayed response or thank you to your questions or answers. ............................
Each computer opponent passes an Arraylist to a common method which selects a playing card and then changes the ImageView to show the playing card.
Resources res = getResources();
int resId = res.getIdentifier(cardSelect, "drawable", getPackageName()); // location of image
Drawable drawable = ResourcesCompat.getDrawable(getResources(), res.getIdentifier(cardSelect, "drawable", getPackageName()), null);
ImageView insertImage = (ImageView) findViewById(R.id.p1CardView);
insertImage.setImageDrawable(drawable);
It uses the same type of coding to update another image on the screen. After the third computer opponent plays, the user's playable cards are marked as clickable and then the program waits for OnClick. At this point the image changes from the computer playing sudden appear with the user marked card instead of when the setImageDrawable is done above. Hope that's helpful!
Thanks