0

2つの画像を切り替えるウィジェットがあり、ユーザーがクリックするたびにウィジェットが変化するので、このウィジェットのレイアウトを次のように定義します

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/parrotstate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:clickable="true"
        android:src="@drawable/widget_awake" />

</RelativeLayout>

AppWidgetProvideclassでは、どの画像が設定されているかを知るために属性 android:src を読み取る必要があります。通常findViewByIdは Activity クラスで使用しますが、ここでは AppWidgetProvide ですclass

4

1 に答える 1

0

おそらくこの質問は重複していますこの投稿を試してみてください:appwidgetproviderでビューIDを見つける方法は?

コンストラクターを使用すると、Remoteviewを取得できます。

RemoteViews(String packageName, int layoutId)
//Create a new RemoteViews object that will display the views contained in the specified layout file.

適用するとビューが返されます

apply(Context context, ViewGroup parent)
//Inflates the view hierarchy represented by this object and applies all of the actions.

リンク:http ://developer.android.com/reference/android/widget/RemoteViews.html

于 2013-03-11T12:04:47.463 に答える