Hi I'm relatively new to android programming, and I need some help with setting up my widget, I'm stuck trying to set the image view resource randomly when the widget updates, I have tried
Random r = new Random();
int min = 001;
int max = 721;
String name = "national" + r.nextInt(max - min + 1) + min;
int id = getResources().getIdentifier(name, "drawable", getPackageName());
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.source);
views.setOnClickPendingIntent(R.id.imgwidg, pendingIntent);
views.setImageViewResource(id);
but it isn't accepting getResources()
or getIdentifier()
what do I do?
Edit: I'm also pretty sure it won't like 001 so how can i format the number to be 3 digits?
Aucun commentaire:
Enregistrer un commentaire