Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:49:06+00:00 2026-05-31T16:49:06+00:00

I am trying to create a widget in android in which when I click

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:49:07+00:00Added an answer on May 31, 2026 at 4:49 pm

    As I suspected, you used the background attribute on your ImageView. background and setImageViewResource are different. Instead, stick with the same code, but change your layout to use src instead of background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a textview with reflection on android but I could not
I'm trying to create a program for Android which will read in text, and
I am trying to create a widget for my android app. I want it
I'm trying to create a widget for Android. It contains such files: res/xml/widgetinfo.xml: <?xml
I am trying to create a popup menu and I keep getting java.lang.NoClassDefFoundError: android.widget.PopupMenu
I'm new to both android and game development and have been trying to create
I have create a widget in android , whenever i click on Widget TextView
I am trying to create a calendar in android which will display the number
I'm trying to create a widget within the module and then load that widget
I'm trying to create an icon/widget (1 cell x 1 cell) that can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.