I have a listView. I needed a custom view for each list item, so I've created a custom ListAdapter which gives the views, layout for which is given below. But how do I set this listAdapter to the ListView in the widget using RemoteViews ?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_light"
android:layout_margin="1sp"
android:padding="10sp"
>
<TextView
android:id="@+id/widgetInfo1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/listItemDummy"
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/widgetInfo2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/listItemDummy"
android:textColor="@android:color/black"
/>
</LinearLayout>
Instead of the common
Adapter
, forRemoteViews
you need to implementRemoteViewsFactory
. To return customRemoteView
's (yes,RemoteView
for each item and notView
), you will need to override itsgetViewAt(int position)
method.Also, one just does not
setAdapter()
forRemoteView
s, you would need to provide aRemoteViewsService
which will return aboveRemoteViewsFactory
to its clients.Finally, to the client that is going to show the
RemoteView
s, you pass anIntent
of this service.The Service and its Intent you will need to declare in your manifest file. This will make your App a provider of remote List like views to other apps or any remote process.