2013-12-19 33 views
0

我想从窗口小部件中显示的ListView中的服务添加项目。但是我怎样才能在服务中获得我的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); 

但现在我怎样才能让我的ListView从RemoteViews?

+0

[这里](https://github.com/laaptu/appwidget-listview/tree/appwidget-listview1)是一个似乎完全符合你需要的例子。 –

回答

1

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

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

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

+0

谢谢你。我尝试过,但小部件不更新。在这里,我发布了我的问题。如果你看看它会很好:http://stackoverflow.com/questions/20704139/listview-in-widget-does-not-update – Cilenco

+0

你能告诉我如何为这个ListView设置一个OnItemClickListener吗? – Cilenco

相关问题