0

我有一个在两个图像之间切换的小部件,每次用户点击它时,小部件都会发生变化所以我为这个小部件定义了一个布局,如下所示

<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 类中使​​用,但这里是 AppWidgetProvideclass

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 回答