DonGru
DonGru

Reputation: 13710

Create drawable resource path dynamically

I have something like the following line of code:

Notification notif = new Notification(R.drawable.notification_XX, "Notify", System.currentTimeMillis());

My problem is that i want to make R.drawable.notification_XX changeable, so for example if I have a variable i = 24; then the appropriate resource R.drawable.notification_24 should be used

So, is there a way of creating a drawable resource path dynamically?

thanks in advance, Martin

Upvotes: 2

Views: 1621

Answers (1)

David Webb
David Webb

Reputation: 193686

If you want to change the Notification to display a number you can just set the number field of your Notification object and the appropriate number will be overlaid over your icon in the Notifications bar.

However, if you really have a number of different icons you can use the getIdentifier() method on Resources which will return the Resource ID for a given name.

Upvotes: 5

Related Questions