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 9076915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:12:53+00:00 2026-06-16T19:12:53+00:00

I want to change one of the visual elements of an android widget when

  • 0

I want to change one of the visual elements of an android widget when the user clicks it. This is in the widget’s xml

    <ImageView
      android:id="@+id/bg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="false"
      android:layout_marginLeft="20dp"
      android:layout_marginTop="18dp"
      android:src="@drawable/seal" />

I want to change the src based on an ID, so from the widget I plan to send the remoteView a click listener

 Intent bgSwitch = new Intent(widgetContext, MainActivity.class);
 bgSwitch.putExtra("jurisdiction", "bg");
 PendingIntent bgIntent = PendingIntent.getActivity(widgetContext,
 6, bgSwitch, PendingIntent.FLAG_UPDATE_CURRENT);
 remoteView.setOnClickPendingIntent(R.id.bg, bgIntent);

and in a transparent activity (or in the widget itself) I want to somehow change the imageview ‘s source.

I don’t want to just flip the visibility of a bunch of imageviews.

how would this be achieved?

  • 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-16T19:12:54+00:00Added an answer on June 16, 2026 at 7:12 pm

    You can try this way:

    public class SwitchWidget extends AppWidgetProvider {
    public static String SWITCH_WIDGET_UPDATE = "MainActivity.Switch";
    public static String WIFI = "wifi";
    
    @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");
    
    
    
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
    
        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(WIFI)) {
    
                if(wifiManager.isWifiEnabled())
                    wifiManager.setWifiEnabled(false);
                else
                    wifiManager.setWifiEnabled(true);
    
    
            // appWidgetManager.updateAppWidget(1, remoteViews);
        }
        else if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
    
    
                remoteViews = new RemoteViews(context.getPackageName(),
                        R.layout.widget1);
                wifiManager = (WifiManager) context
                        .getSystemService(Context.WIFI_SERVICE);
                if (wifiManager.isWifiEnabled()) {
                    remoteViews.setImageViewResource(R.id.button_one,
                            R.drawable.switch_1_wifi_on);
                } else {
    
                    remoteViews.setImageViewResource(R.id.button_one,
                            R.drawable.switch_1_wifi_off);
                }
                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);
    
    
        WifiManager wifi = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        if (wifi.isWifiEnabled())
            remoteViews.setImageViewResource(R.id.button_one, R.drawable.switch_1_wifi_on);
        else
            remoteViews
                    .setImageViewResource(R.id.button_one, R.drawable.switch_1_wifi_off);
    
        Intent wifiIntent = new Intent(context, SwitchWidget.class);
        wifiIntent.putExtra("ID", appWidgetId);
        wifiIntent.setAction(WIFI);
        PendingIntent wifiPendingIntent = PendingIntent.getBroadcast(context,
                0, wifiIntent, 0);
        remoteViews.setOnClickPendingIntent(R.id.button_one, wifiPendingIntent);
    
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
    
      }
    

    And also don’t forget to add action in your manifest file and also add permissions for that.

         <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
                <action android:name="wifi" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change the background screens of one of my Blackberry app and
I want to change out my previous main form for a new one. According
I want to change the background color of the page when one hovers over
I have a image, and i want it to change to another one when
I want to modify the index of one (text) file without having to change
I know very little about visual studio so the answer to this one might
I'm using Crystal Reports in Visual Studio 2003 and i want to automatically change
Say you just want to get rid of the changes you've made to one
i want change the content of a UITableView when i change a button, how
I want change following javascript code to jquery code, How is it? With done

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.