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