我有一个列表视图。我需要为每个列表项提供一个自定义视图,因此我创建了一个自定义 ListAdapter,它提供了视图和布局,如下所示。但是如何使用 RemoteViews 将这个 listAdapter 设置为小部件中的 ListView ?
<?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>
而不是常见的Adapter
, for RemoteViews
你需要实施RemoteViewsFactory。返回定制RemoteView
的(是的,RemoteView
对于每个项目而不是View
),你需要覆盖它的getViewAt(int position) method.
另外,一个人只是不setAdapter()
for RemoteView
s,您需要提供RemoteViewsService这将返回上面RemoteViewsFactory
给其客户。
最后,向要展示的客户RemoteView
s,你通过了Intent
这项服务的。
您需要在清单文件中声明该服务及其意图。这将使您的应用程序成为远程列表的提供者,例如其他应用程序或任何远程进程的视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)