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

  • SEARCH
  • Home
  • 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 9206999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:17:44+00:00 2026-06-18T00:17:44+00:00

I design an android app widget in which two ImageView i want change the

  • 0

I design an android app widget in which two ImageView i want change the image both of the the ImageView when click on the image as well as call a method.
Now i use RemoteView like this

RemoteViews views1 = new RemoteViews(context.getPackageName(),
                R.layout.activity_main);
        views1.setOnClickPendingIntent(R.id.smsImageView, pendIntent1);
        appWidgetManager.updateAppWidget(appWidgetIds, views1);

but i have no idea how i change the image in imageView
Thanks.

  • 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-06-18T00:17:45+00:00Added an answer on June 18, 2026 at 12:17 am

    Widget_Layout :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="horizontal" >
    
        <ImageView
            android:id="@+id/imageview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/imageview1_image1"/>
    
        <ImageView
            android:id="@+id/imageview2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:src="@drawable/imageview2_image1" />
    
    </LinearLayout>
    

    In your AppWidgetProvider :

    public class SwitchWidget extends AppWidgetProvider {
    public static String SWITCH_WIDGET_UPDATE = "MainActivity.Switch";
    public static String IMAGEVIEW1 = "imageview1";
    public static String IMAGEVIEW2 = "imageview2";
    
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        // TODO Auto-generated method stub
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        updateSwitch1(context, appWidgetManager, appWidgetIds[0]);
    }
    
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onReceive(context, intent);
        Log.d("SWitch Widget", "On Receive");
    
    
    
    
        RemoteViews remoteViews;
    
        AppWidgetManager appWidgetManager = AppWidgetManager
                .getInstance(context);
    
        if (SWITCH_WIDGET_UPDATE.equals(intent.getAction())) {
            Log.d("SWitch Widget", "Widget Choose");
            ComponentName thisAppWidget = new ComponentName(
                    context.getPackageName(), getClass().getName());
    
            int ids[] = appWidgetManager.getAppWidgetIds(thisAppWidget);
            for (int appWidgetID : ids) {
    
                    updateSwitch1(context, appWidgetManager, appWidgetID);
                } 
    
            }
    
        }
        if (intent.getAction().equals(IMAGEVIEW1)) {
    
    
    
    
                remoteViews = new RemoteViews(context.getPackageName(),
                        R.layout.widget1);
                if(flag){
                flag = flase           
                    remoteViews.setImageViewResource(R.id.imageview1,
                            R.drawable.imageview1_image2);
                     startService(new Intent(this, YOUR_SERVICE_CLASS_NAME.class)); 
                } else {
                flag = true;
                    remoteViews.setImageViewResource(R.id.imageview1,
                            R.drawable.imageview1_image1);
                    startService(new Intent(this, YOUR_SERVICE_CLASS_NAME.class));
                }
                appWidgetManager.updateAppWidget(new ComponentName(context,
                        SwitchWidget.class), remoteViews);
    
    
            }
            else if (intent.getAction().equals(IMAGEVIEW2)) {
    
                remoteViews = new RemoteViews(context.getPackageName(),
                        R.layout.widget1);
                if(flag){
             flag = flase          
                    remoteViews.setImageViewResource(R.id.imageview2,
                            R.drawable.imageview2_image2);
                } else {
            flag = true;
                    remoteViews.setImageViewResource(R.id.imageview2,
                            R.drawable.imageview2_image1);
                }
                appWidgetManager.updateAppWidget(new ComponentName(context,
                        SwitchWidget.class), remoteViews);
    
          }
    
    
    
    private void updateSwitch1(Context context,
            AppWidgetManager appWidgetManager, int appWidgetId) {
        // TODO Auto-generated method stub
        Log.d("SWitch Widget", "Switch1");
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.widget1);
    
    
    
        Intent imageview1Intent= new Intent(context, SwitchWidget.class);
        wifiIntent.putExtra("ID", appWidgetId);
        wifiIntent.setAction(IMAGEVIEW1);
        PendingIntent imageview1PendingIntent = PendingIntent.getBroadcast(context,
                0, imageview1Intent,0);
        remoteViews.setOnClickPendingIntent(R.id.imageview1, imageview1PendingIntent);
    
        Intent imageview2Intent= new Intent(context, SwitchWidget.class);
        wifiIntent.putExtra("ID", appWidgetId);
        wifiIntent.setAction(IMAGEVIEW2);
        PendingIntent imageview2PendingIntent = PendingIntent.getBroadcast(context,
                0, imageview2Intent,0);
        remoteViews.setOnClickPendingIntent(R.id.imageview2, imageview2PendingIntent);
    
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
    
      }
    

    And also in your widget receiver add this two actions :

     <action android:name="imageview1" />
      <action android:name="imageview2" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to design a login and register layout using android tabs. Image is
I'm working on an Android app which has an activity and a widget. This
I want to develop a new Android app. Design guidelines for Droid 3.0+ encourage
In my android app, I need to design a Welcome Screen which will be
I have a simple question. I am trying to design a simple Android app,
During our efforts to design InApp Billing for our Android App, we came up
Possible Duplicate: Android Layout and positioning issue Design layout which support for all kind
I am Trying to 'design' First native app for android. To start with this
I have an android app for which i need to ensure that it has
For an android app with a custom design, I open the keyboard manually as

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.