【问题标题】:Get ListView from widget layout从小部件布局中获取 ListView
【发布时间】:2013-12-19 15:04:51
【问题描述】:

我想在小部件中显示的 ListView 中添加来自服务的项目。但是如何在服务中获取我的 ListView?我的小部件布局如下所示:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</ListView>

通过这段代码,我可以从我的小部件中获取 RemoteViews:

AppWidgetManager mgr = AppWidgetManager.getInstance(ctx);
RemoteViews rv = new RemoteViews(ctx.getPackageName(), R.layout.widget_layout);

但是现在我怎样才能从 RemoteViews 中获取我的 ListView?

【问题讨论】:

  • Here 是一个似乎完全符合您需要的示例。

标签: android listview widget remoteview


【解决方案1】:

您将需要一个 RemoteViewFactory 类,它是您的 ListView 的适配器;

rv.setRemoteAdapter(appWidgetId, R.id.listView1,
                            serviceIntent);

通过this 链接。我想这正是你想要的。

【讨论】:

  • 谢谢。我试过了,但小部件没有更新。在这里,我发布了我的问题。如果你acn看看就好了:stackoverflow.com/questions/20704139/…
  • 你能告诉我如何为这个 ListView 设置 OnItemClickListener 吗?
猜你喜欢
  • 2011-03-05
  • 1970-01-01
  • 2012-04-11
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多