-->

如何设置自定义ListAdapter列表视图中appwidget?(How to set custo

2019-07-19 15:33发布

我有一个ListView。 我需要为每个列表项的自定义视图,所以我创建了一个自定义的ListAdapter这给意见,布局其下面给出。 但我怎么设置这个listAdapter在使用RemoteViews该插件的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>

Answer 1:

取而代之的是普通的Adapter ,用于RemoteViews需要实现RemoteViewsFactory 。 要返回定制RemoteView的(是的, RemoteView每个项目,而不是View ),您将需要重写它的getViewAt(int position)的方法。

此外,一个少了点setAdapter()用于RemoteView S,你就需要提供一个RemoteViewsService将返回上述RemoteViewsFactory向它的客户。

最后,是要显示在客户端RemoteView S,你传递一个Intent这项服务。

服务及其意图,你需要在你的清单文件中声明。 这会让你的应用程序一样的观点遭到其他应用程式或任何远程过程的远程清单的提供者。



文章来源: How to set custom ListAdapter to list view in appwidget?