Looked through every question, can’t get it working.
I wanna set an AppWidgets layout with the value of a string (So the layout can be switched to another one by just changing the string).
String NoteString = "R.layout.widget_blue".toString();
int resID = context.getResources().getIdentifier(NoteString, "layout", context.getPackageName());
RemoteViews views = new RemoteViews(context.getPackageName(), resID);
don’t know why it doesn’t work, widget just says: “problem loading widget”..
This works fine:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_blue);
Thanks
In order to construct a resource ID from string components, you must pass the individual components into
getIdentifier(), not the fully qualified ID as a single parameter:Then just change the first parameter name to get a different layout resource.