android自定义通知的问题

llller 2012-04-17 04:53:24

通过加载静态的xml,可以弹出通知..
如果现在我的xml是动态生成的呢,该怎么做..


public class Notice {
private static final int notification_ID = 0x6238;
private static final int layout_id = 0x23529568;
private static final int img_id = 0x23520068;

private Notification noticed;
private NotificationManager noticedManager;
private PendingIntent pi;
private Context context;
private String pkgName = "";
private RemoteViews rv = null;
private LinearLayout ll = null;
private ImageView img = null;

public Notice(Context _context, String pkgname) {
this.context = _context;
pkgName = pkgname;
noticed = new Notification();
Intent intent = new Intent(context, ShowActivity.class);

pi = PendingIntent.getActivity(context, 0, intent, 0);
noticedManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
makeLayout();
rv = new RemoteViews(pkgName, layout_id);
}

public void updateNotification(String tipsText, int contentImageID){
noticed.icon = R.drawable.def_icon;
noticed.tickerText = tipsText;
noticed.when = System.currentTimeMillis();
rv.setImageViewResource(img_id, contentImageID);
noticed.contentView = rv;
noticed.contentIntent = pi;
noticedManager.notify(notification_ID, noticed);
}

public void cancelNotification(){
noticedManager.cancel(notification_ID);
}

private void makeLayout(){
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
ll = new LinearLayout(context);
ll.setLayoutParams(lp);
ll.setId(layout_id);
img = new ImageView(context);
img.setLayoutParams(lp);
img.setScaleType(ScaleType.FIT_XY);
img.setId(img_id);

ll.addView(img);
}

}


但是执行后,报错:
android.content.res.Resources$NotFoundException: Resource ID #0x23529568

我知道是layout在系统里找不到...


如果要用动态生成的xml的话,改怎么弄????
...全文
166 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
深夜深几许 2013-09-02
  • 打赏
  • 举报
回复
引用 2 楼 j68205150 的回复:
[Quote=引用 1 楼 的回复:] 动态生成XML??这是编译产物不好动态吧 如果说布局不固定,可以考虑代码布局 [/Quote] 我们说的是同一个东西,我指的就是动态布局.. 就是makeLayout方法里的..
老兄,你的问题解决了么?
llller 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

动态生成XML??这是编译产物不好动态吧
如果说布局不固定,可以考虑代码布局
[/Quote]

我们说的是同一个东西,我指的就是动态布局..
就是makeLayout方法里的..
破折号 2012-04-18
  • 打赏
  • 举报
回复
动态生成XML??这是编译产物不好动态吧
如果说布局不固定,可以考虑代码布局

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧