我正在开发一个简单的C#Android 应用程序,它在后台运行并执行特定计算,我还有一个带有 TexTview 的小部件,我想在其中显示计算结果。服务.csIntent intent = new Intent("TEST");intent.PutExtra("alltotale", total.ToString());this.SendBroadcast(intent);然后在BroadcastReceiver课堂上,我有:接收器.cs public override void OnReceive(Context context, Intent intent) { string nh = intent.GetStringExtra("alltotale"); Toast.MakeText(context, nh, ToastLength.Short).Show(); }现在我想重新使用这个值并将它显示在小部件 TextView 中,但它不起作用,我的Widget.AppWidget.cs[BroadcastReceiver(Label = "Widget1")][IntentFilter(new string[] { "android.appwidget.action.APPWIDGET_UPDATE" })][MetaData("android.appwidget.provider", Resource = "@xml/appwidgetprovider")]public class AppWidget : AppWidgetProvider{ Intent intent; public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { var me = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name); appWidgetManager.UpdateAppWidget(me, BuildRemoteViews(context, appWidgetIds)); } private RemoteViews BuildRemoteViews(Context context, int[] appWidgetIds) { var widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget); SetTextViewText(widgetView); RegisterClicks(context, appWidgetIds, widgetView); return widgetView; } private void SetTextViewText(RemoteViews widgetView) { string oo = intent.GetStringExtra("alltotale"); widgetView.SetTextViewText(Resource.Id.widgetMedium, "Dabboussi"); widgetView.SetTextViewText(Resource.Id.widgetSmall, oo); } private static string AnnouncementClick = "AnnouncementClickTag";因此,该值显示Toast在后台的消息中,但没有显示在小部件中textview。为什么会这样,我该如何解决?
2 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
你输入了一个名为 named 的字符串alltotale
,你要求一个名为 的字符串widgetTotale
,所以如果它不起作用是正常的。你必须改变widgetTotale
由alltotale
- 2 回答
- 0 关注
- 174 浏览
添加回答
举报
0/150
提交
取消