如何访问一个ViewFlipper在一个Widget动态填充它的内容? [英] How do I access a ViewFlipper in a Widget to populate its content dynamically?

查看:233
本文介绍了如何访问一个ViewFlipper在一个Widget动态填充它的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要动态内容来填充一个小部件。

具体来说,我想它含有ViewFlipper他们的观点在运行时被更新。

我不是如何从的方法的onUpdate访问ViewFlipper清楚我的 AppWidgetProvider (假设这是正确的地方,影响到小部件,并改变一切例子我发现在网上处理有在XML中定义的所有它们的元素)静态布局。

所以...

  @覆盖
公共无效的onUpdate(上下文的背景下,AppWidgetManager appWidgetManager,
        INT [] appWidgetIds){
    RemoteViews remoteViews =新的RemoteViews(context.getPackageName(),R.layout.widget_layout);    //伪code我正在寻找的东西,让我做到这一点?
    **(ViewFlipper)VF = remoteViews.findViewById(R.id.myFlipper)**//编辑:
基于commonsware的建议// ...我在这里...
ImageView的stationView =(ImageView的)((活动)上下文).getLayoutInflater()膨胀(R.layout.widget_station,NULL);//怎么样呢?    pushWidgetUpdate(背景下,remoteViews);}

然而, RemoteViews 没有这样的方法,所以,我很困惑,如何处理这个问题。我根据文档窗口小部件支持ViewFlippers看到...但他们不支持动态填充它们?


解决方案

  

具体来说,我想它含有ViewFlipper他们的观点在运行时更新


有两种可能的跨$这一请求的对$ ptations。

一个是你想要的 ViewFlipper 持有固定数量的页面,而每个页始终具有相同的部件,但你要填充这些小部件的内容。在这种情况下,您填充他们,你做任何事情在应用程序插件的方式相同:参照这些特定的部件,忽略了 ViewFlipper

或者,你想有一个 ViewFlipper ,在不同的时代已经变化的页数,或在页面有不同的布局。在这种情况下,你可以尝试 addView()的每一页,指定 ViewFlipper id作为第一个参数。或者,尝试 AdapterViewFlipper ,看看 setRemoteAdapter()将导致应用程序部件从<$重新加载其内容C $ C> RemoteViewsService 。

I have a Widget that needs to be populated with dynamic content.

Specifically I'd like it to contain a ViewFlipper whose Views are updated at runtime.

I'm not clear on how to access the ViewFlipper from the onUpdate method of my AppWidgetProvider (assuming this is the correct place to affect change on the Widget and all the examples I'm finding on-line deal with static layouts that have all their elements defined in the xml).

So...

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

    //in pseudo code I'm looking for something that lets me do this...
    **(ViewFlipper) vf = remoteViews.findViewById(R.id.myFlipper);**

//EDIT:
//based on commonsware's suggestion... I'm here...
ImageView stationView = (ImageView)((Activity)context).getLayoutInflater().inflate(R.layout.widget_station, null);

//how what?

    pushWidgetUpdate(context, remoteViews);

}

However, RemoteViews doesn't have such a method, so, I'm perplexed as to how to handle this. I see according to the docs that Widgets support ViewFlippers... but do they not support populating them dynamically?

解决方案

Specifically I'd like it to contain a ViewFlipper whose Views are updated at runtime

There are two possible interpretations of this request.

One is that you want the ViewFlipper to hold a fixed number of "pages", and each "page" always has the same widgets, but you want to populate the contents of those widgets. In that case, you populate them the same way that you do anything else in an app widget: by referring to those specific widgets, ignoring the ViewFlipper.

Or, you want a ViewFlipper that has varying number of pages at different times, or where the pages have varying layouts. In that case, you can try addView() for each page, specifying the ViewFlipper id as the first parameter. Or, try AdapterViewFlipper, and see if setRemoteAdapter() will cause the app widget to reload its contents from the RemoteViewsService.

这篇关于如何访问一个ViewFlipper在一个Widget动态填充它的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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