Android 小部件:addView 无法与 RemoteViews 对象一起使用
我想在运行时将文本视图添加到我的小部件中。我看到很多教程,其中 RemoteViews 对象调用 addView 方法将视图添加到某些布局。
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
TextView t = new TextView(context);
views.addView(R.id.view_container, t);
appWidgetManager.updateAppWidget(thisWidget, views);
但是 addView 方法显示此错误: The method addView(int, RemoteViews) is undefined for the type RemoteViews.True, this method is Define for the ViewGroup class,但为什么它对每个人都有效?有没有办法在运行时将文本视图添加到某些 RemoteViews 中?
I want to add textviews to my widget on runtime. I saw many tutorials where RemoteViews object calls addView method to add a view to some layout.
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
TextView t = new TextView(context);
views.addView(R.id.view_container, t);
appWidgetManager.updateAppWidget(thisWidget, views);
But addView method shows this error: The method addView(int, RemoteViews) is undefined for the type RemoteViews.True, this method is defined for the ViewGroup class, but why is it working for everyone then? And is there a way to add textviews to some RemoteViews on runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
签名不是 <代码>RemoteViews.addView(int, RemoteViews)?
您似乎有一个
TextView
作为第二个参数。像这样的东西应该有效:
Isn't the signature
RemoteViews.addView(int, RemoteViews)
?You seem to have a
TextView
as the second parameter.Something like this should work: