3

私はリストビューを持っています。リスト項目ごとにカスタム ビューが必要だったので、以下に示すレイアウトのビューを提供するカスタム 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>
4

1 に答える 1

4

Adapter一般的な の代わりに、RemoteViewsを実装する必要がありますRemoteViewsFactory。カスタムの を返すにはRemoteView(はい、RemoteViewアイテムごとであり、 ではありません)、そのメソッドViewをオーバーライドする必要があります。getViewAt(int position)

setAdapter()また、 s には対応していません。クライアントに上記を返すRemoteViewa を提供する必要があります。RemoteViewsServiceRemoteViewsFactory

最後に、 を表示するクライアントに、このサービスのRemoteViewを渡します。Intent

マニフェスト ファイルで宣言する必要があるサービスとそのインテント。これにより、アプリは、他のアプリまたは任意のリモート プロセスへのビューのようなリモート リストのプロバイダーになります。

于 2013-02-09T06:11:29.783 に答える