this.user3272243
this.user3272243

Reputation: 1246

setting image drawable from a class

I'm trying to set an image from a non Activity class, the drawable name is saved in a string and comes from another methor but the problem is that getPackageName() gives me this error: "cannot resolve method 'getPackageName()'" and I have no idea what to do, here is my code:

String[] string = printArray(false, context);

image1.getResources().getIdentifier(string[0] , "drawable", getPackageName());
image2.getResources().getIdentifier(string[1] , "drawable", getPackageName());
image3.getResources().getIdentifier(string[2] , "drawable", getPackageName());

Upvotes: 0

Views: 330

Answers (1)

Lena Bru
Lena Bru

Reputation: 13947

try image1.getContext().getPackageName()

Upvotes: 1

Related Questions