【问题标题】:Android 'Couldn't expand remoteViews for...' when creating layout programmatically以编程方式创建布局时,Android“无法为...扩展 remoteViews”
【发布时间】:2013-11-09 19:16:34
【问题描述】:

我正在尝试以编程方式构建自己的布局,然后“构建”RemoteViews 并将其显示为通知。

骨架:

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());

对于每个布局,我通过此处介绍的方法设置LayoutParamsorientationIDhttps://stackoverflow.com/a/15442898/1405268

当我尝试使用 RemoteViews 启动通知时,我收到“从包 XXX 发布的错误通知:无法为 StatusBarNotification 展开 RemoteViews...

谢谢

【问题讨论】:

    标签: android android-layout notifications android-linearlayout remoteview


    【解决方案1】:

    我正在尝试以编程方式构建自己的布局,然后“构建”RemoteViews 并将其显示为通知

    传递给RemoteViews 构造函数的ID 需要是布局资源ID。然后,您需要使用 RemoteViews 上的方法来尝试构建您的结构,尽管我怀疑它是否会起作用。

    【讨论】:

    • 为什么可以给ResourceID而不生成唯一ID?
    • @SagiLow:首先,两者没有关系。其次,文档说您需要提供布局资源 ID。第三,RemoteViews 背后的意义是将 UI 定义发送给其他进程,而该进程无权访问您的 Java 对象(例如,LinearLayout)。
    猜你喜欢
    • 2017-11-28
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 2018-10-08
    • 2012-08-07
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    相关资源
    最近更新 更多