SagiLow
SagiLow

Reputation: 6029

Android 'Couldn't expand remoteViews for...' when creating layout programmatically

I'm trying to build my own layout programmatically then 'building' RemoteViews and show it as a notification.

Skeleton :

LinearLayout baseLayout = new LinearLayout(context);
for (X) {
    LinearLayout innerLayout = new LinearLayout(context);
        for (Y) {
            TextView textV = new TextView(context);
        }
        innerLayout.addView(textV);
    }
    baseLayout.addView(innerLayout);
}
RemoteViews remoteView = new RemoteViews(getPcakageName(), baseLayout.getId());

For each Layout I set LayoutParams, orientation and ID from the method presented here : https://stackoverflow.com/a/15442898/1405268.

When I try to start the notification with the RemoteViews, I get `Bad notification posted from package XXX: Couldn't expand RemoteViews for StatusBarNotification...

Thanks

Upvotes: 1

Views: 941

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

I'm trying to build my own layout programmatically then 'building' RemoteViews and show it as a notification

The ID passed to the RemoteViews constructor needs to be a layout resource ID. You then need to use methods on RemoteViews to attempt to build your structure, though I am dubious that it will work.

Upvotes: 2

Related Questions