如何在小工具使用onAppWidgetOptionsChanged()? [英] How to use onAppWidgetOptionsChanged() in a widget?

查看:122
本文介绍了如何在小工具使用onAppWidgetOptionsChanged()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每一个它被调整的时间来更新我的窗口小部件。我想通了,这是在做:

onAppWidgetOptionsChanged(上下文的背景下,AppWidgetManager appWidgetManager,INT appWidgetId,捆绑newOptions)

但我不能找出如何更新它的部件。我试图通过调用我把的OnUpdate()一切重绘窗口小部件,但它不工作。我如何可以利用包的?

解决方案
  

我想每一个它被调整的时间来更新我的窗口小部件。

酷!

  

我想通了,这是在 onAppWidgetOptionsChanged做()

更准确的说,如果你有正确的行动,你的&LT;意向滤光器&gt; ,在Android 4.1及更高版本的设备,你会发现通过<关于调整事件code> onAppWidgetOptionsChanged()。

  

但我不能找出如何更新的小部件了。

您更新你的的onupdate更新它以同样的方式()。呼叫 updateAppWidget() AppWidgetManager 与适当的 RemoteViews

  

我试图通过调用一切,我把的OnUpdate()重绘窗口小部件,但它不工作。

它不工作是不是你的症状特别有效的说明。

  

我如何能够利用捆绑?

对于捆绑 newOptions ,你可以找到通过新的尺寸范围:

  newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
 

例如, 包含此示例项目的 AppWidgetProvider ,简单地注入这些值转换为字符串,并使用该更新的TextView 。其结果是这样的:

I would like to update my widget every time it gets resized. I figured out that this is done in:

onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)

But I can't find out how to update the widget in it. I tried to redraw the widget by calling everything that I put in onUpdate(), but it's not working. How can I make use of the bundle?

解决方案

I would like to update my widget every time it gets resized.

Cool!

I figured out that this is done in onAppWidgetOptionsChanged()

More accurately, if you have the right actions in your <intent-filter>, on Android 4.1+ devices, you will find out about resize events via onAppWidgetOptionsChanged().

But I can't find out how to update the widget in it.

You update it the same way you update it in onUpdate(). Call updateAppWidget() on the AppWidgetManager with an appropriate RemoteViews.

I tried to redraw the widget by calling everything that I put in onUpdate(), but it's not working.

"it's not working" is not a particularly effective description of your symptoms.

How can I make use of the bundle?

For a Bundle named newOptions, you can find out your new size range via:

newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)

For example, this sample project contains an AppWidgetProvider that simply pours those values into a string and uses that to update a TextView. The result looks like:

这篇关于如何在小工具使用onAppWidgetOptionsChanged()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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