2013-12-19 36 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

相關問題