Image overlapping in widget

Posted by Hunt on Stack Overflow See other posts from Stack Overflow or by Hunt
Published on 2012-03-16T18:56:50Z Indexed on 2012/03/19 18:03 UTC
Read the original article Hit count: 263

Filed under:
|

I am trying to create a widget in android in which when I click over image the image gets changed with a new one -- kind of toggle image.

But when I click over it, the image overwrites over the old one rather then replacing the new one. I don't know whether this is the way the widget works or am I doing something wrong.

My images are semi-transparent so in case one overrides another one can see the image which is being overlapped.

This is the code that I have written in OnReceive by overriding it:

 @Override 
      public void onReceive(Context context, Intent intent){ 

               if (intent.getAction().equals(iAlertConstant.ACTION_WIDGET_UPDATE_FROM_WIDGET)) {                   


                   RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.mywidget);
                   remoteViews.setImageViewResource(R.id.btnOnOff,R.drawable.offbtn);                  
                   ComponentName thisWidget = new ComponentName(context, EmergencyWidget.class); 
                   AppWidgetManager.getInstance(context).updateAppWidget(thisWidget, remoteViews);         



               }
               else 
                    super.onReceive(context, intent);         


      }

Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:background="@drawable/widget_background"
   android:paddingLeft="10.0dip" 
   android:paddingTop="8.0dip"
   android:paddingRight="10.0dip" 
   android:paddingBottom="8.0dip" 
   android:layout_width="fill_parent" 
   android:layout_height="72dp" 
   android:layout_marginLeft="10.0dip" 
   android:layout_marginTop="10.0dip" 
   android:layout_marginRight="10.0dip"  
   android:id="@+id/emergencyWidget"

   android:orientation="horizontal">

        <ImageView
            android:background="@drawable/offbtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:layout_gravity="right"      
            android:id="@+id/btnOnOff"

     />



</LinearLayout>

© Stack Overflow or respective owner

Related posts about android

Related posts about android-widget