Manish Jha
Manish Jha

Reputation: 33

How do I add a source to a imageView in android when the image is supposed to be set dynamically?

I am making a card game (with 3 CPU players and one human player), the human player has 10 cards at the start of the game and I am not sure how to attach the cards to their respective image view since the deck is shuffled before dealing the cards to the players so, the cards that the human player has depends on how the deck was shuffled before dealing.

The human player's card go down by one each round and disappear since he has to play one card each round and each player is started off with 10 cards. My problem here is since every time you start a new round the player has 10 different cards.. I am not sure how my card images are going to update since the source of the cards would now be different. I have 10 static image views inside a relative layout.

I am not sure how to approach this problem.. should I attach each card with its image before dealing them? and if so how would I go about doing it?

Upvotes: 1

Views: 60

Answers (1)

jonathanrz
jonathanrz

Reputation: 4296

You provided very little context, so it is difficult to provide a good solution.

If the views at the screen will be always visible and you will have always 10, you can set them statically and load the image into each one.

If the views are dynamic, you could use a recycler view.

For loading the images, you can load them programatically.

Handling Bitmaps in Android is annoying, so you should use a library to help you, picasso or glide are two excellent options.

Upvotes: 1

Related Questions