通过加载静态的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的话,改怎么弄????
解决方案 »
- viewpager和TabHost使用,activity刷新问题
- 求解:设定默认闹钟铃声需要申明神马权限?
- android PC 连接问题
- ubuntu下如何用ADB通过网络和平板相连进行调试
- remoteviews如何里取得某个控件的属性?
- 2.2程序完全退出,现在有好的办法吗
- edittext 圆角显示加上最左边有不可点击的文本,请问大神们该怎么做呢,上图
- avd运行一次少1g磁盘空间?
- android 集成了facebook之后再有app的情况下不能登录
- 自定义上下滑动引导界面,点击最后的button按钮就报错
- android文件下载遇到两个问题,请大侠来解决!!
- 服务器端向Android客户端返回数据显示
如果说布局不固定,可以考虑代码布局
我们说的是同一个东西,我指的就是动态布局..
就是makeLayout方法里的..
我们说的是同一个东西,我指的就是动态布局..
就是makeLayout方法里的..老兄,你的问题解决了么?