无法在小部件中调用TextClock的setFormat24Hour [英] Can't call setFormat24Hour of a TextClock in a Widget

查看:349
本文介绍了无法在小部件中调用TextClock的setFormat24Hour的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态更新小部件的TextClock的format24Hour.

I'm trying to dynamically update the format24Hour of my Widget's TextClock.

为此,我使用的是RemoteViews,如下所示:

To do so I'm using RemoteViews like so:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.clockwidget);
views.setString(R.id.textclock, "setFormat24Hour", formatString24.toString());
appWidgetManager.updateAppWidget(appWidgetId, views);

但是,这会使我的窗口小部件显示问题加载窗口小部件",而logcat显示

This however causes my Widget to show "Problem loading Widget" and logcat shows

 03-31 17:37:19.872: W/AppWidgetHostView(1408): updateAppWidget couldn't find any view, using error view
 03-31 17:37:19.872: W/AppWidgetHostView(1408): android.widget.RemoteViews$ActionException: view: android.widget.TextClock doesn't have method: setFormat24Hour(class java.lang.String)

但是,我很确定android.widget.TextClock具有标记为@RemotableViewMethod的方法setFormat24Hour(CharSequence format).

However I'm pretty sure that android.widget.TextClock has a method setFormat24Hour(CharSequence format) which is marked as @RemotableViewMethod.

有什么我想念的吗?为什么这行不通?

Is there anything I'm missing? Why isn't this working?

推荐答案

感谢njzk2,我找到了解决方案.这是一个相当愚蠢的问题. 我需要调用RemoteViews#setCharSequence而不是setString,然后一切正常!

Thanks to njzk2 I found the solution. It was a rather stupid problem. I need to call RemoteViews#setCharSequence instead of setString and then everything works fine!

这篇关于无法在小部件中调用TextClock的setFormat24Hour的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆