0

I have a Widget that toggles between two images, the widget changes each time a user clicks on it So I define a layout for this widget as follows

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

In the AppWidgetProvide class, I need to read the attribute android:src to know which image is set. Normally I use findViewById in the Activity class but here it is AppWidgetProvide class

Triode
  • 11,309
  • 2
  • 38
  • 48
yasserbn
  • 391
  • 3
  • 18
  • probably this question is duplicated try with this post http://stackoverflow.com/questions/4666687/how-to-find-view-id-in-appwidgetprovider – ƒernando Valle Mar 11 '13 at 11:56
  • I know I should use RemoteViews but it does not have a function to access the imageView – yasserbn Mar 11 '13 at 11:58
  • why dont get the count with a boolean? is not difficult the implementation. I will post you an example if you want. – ƒernando Valle Mar 11 '13 at 12:00
  • This boolean maybe killed if declared inside onReceive() of the AppWidgetProvider(). Where should I define it to be saved all the time and read it when clicking on the Widget – yasserbn Mar 11 '13 at 12:04

1 Answers1

0

probably this question is duplicated try with this post: How to find view id in appwidgetprovider?

With the constructor you can get the Remoteview:

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

apply returns the view

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

link: http://developer.android.com/reference/android/widget/RemoteViews.html

Community
  • 1
  • 1
ƒernando Valle
  • 3,634
  • 6
  • 36
  • 58