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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:02:02+00:00 2026-05-31T21:02:02+00:00

I have create a widget in android , whenever i click on Widget TextView

  • 0

I have create a widget in android , whenever i click on Widget TextView one service get starts but at the same time i want to change the icon which is shown on the right side.

I can set a onclick over Widget TextView using

remoteViews.setOnClickPendingIntent(R.id.widgetTxt,pendingIntent);

but i don’t know where i can change the icon when the TextView get clicks

image
enter image description here

@Override
        public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {

                        // Here i am trying to set a onclick over TextView
    Intent intent = new Intent(context,MyService.class);
            PendingIntent pendingIntent = PendingIntent.getService(context,0 , 
                    intent, 0);

            remoteViews.setOnClickPendingIntent(R.id.MyWidgetTxt,pendingIntent);

    }

When an icon itself gets clicked , it changes too and i have set its code in onReceive

  • 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-31T21:02:05+00:00Added an answer on May 31, 2026 at 9:02 pm

    try this :

    In manifest.xml

     <receiver android:name="TestwidgetProvider"
                android:label="@string/widget_title" android:exported="false" android:icon="@drawable/test">
                <intent-filter>
                    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                    <action android:name="com.imranandroid.demo.ACTION_ON_ImG_CLICK"/>
                    <action android:name="android.appwidget.action.APPWIDGET_DELETED"/>
                </intent-filter>
                <meta-data android:name="android.appwidget.provider"
                    android:resource="@xml/widget_info" />
            </receiver>
    

    In AppWidgetProvider.java :

      public class TestwidgetProvider extends AppWidgetProvider {
            public static final String TAG_IMAGE_CLICK = "com.imranandroid.demo.ACTION_ON_ImG_CLICK";
            public static RemoteViews rview;
    public static int ii=0;
            @Override
            public void onUpdate(Context paramContext, AppWidgetManager appWidgetManager, 
                    int[] appWidgetIds){
                //REMOVE YOUR CODE FROM HERE
                updateWidgetState(paramContext, "");    
            }
            @Override
            public void onReceive(Context paramContext, Intent paramIntent)
              {
                 String str = paramIntent.getAction();
                if (paramIntent.getAction().equals(TAG_IMAGE_CLICK)) {
                    updateWidgetState(paramContext, str);   
                }
                else
                {
                  super.onReceive(paramContext, paramIntent);
                }
              }
             static void updateWidgetState(Context paramContext, String paramString)
              {
                RemoteViews localRemoteViews = buildUpdate(paramContext, paramString); //CALL HERE
                ComponentName localComponentName = new ComponentName(paramContext, TestwidgetProvider.class);
                AppWidgetManager.getInstance(paramContext).updateAppWidget(localComponentName, localRemoteViews);
              }
         private static RemoteViews buildUpdate(Context paramContext, String paramString)
          {
             rview = new RemoteViews(paramContext.getPackageName(), R.layout.widget_layoutmain);
             Intent active = new Intent(paramContext, TestwidgetProvider.class); //YOUR WIDGET NAME
             active.setAction(TAG_IMAGE_CLICK);
             PendingIntent actionPendingIntent = PendingIntent.getBroadcast(paramContext, 0, active, 0);
             rview.setOnClickPendingIntent(R.id.MyWidgetTxt, actionPendingIntent);
             if (paramString.equals(TAG_IMAGE_CLICK)) {
             if(ii==0)
                {
                rview.setImageViewResource(R.id.ImageView01a, R.drawable.off);
                        ii=1;
                }
                else
                {
                rview.setImageViewResource(R.id.ImageView01a, R.drawable.on);
                        ii=0;
                }
                }
             return rview;
          }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 questions to ask here. I am refering http://www.broculos.net/en/article/android-101-how-create-stackview-widget to create a
I have created an App Widget for Android 1.5. It uses a TextView to
I have create a class that extends BaseAdapter . At the same time, tt
Is there a way to have the android.widget.AnalogClock display a preset time? I don't
I just want get my video playUrl in android.... I have checked the relevant
I have create android listview that fill in using String array. I want to
I have an Android app I made and everything works but I want to
I have problem with Qt::Tool flag. When I create new widget with Qt::Tool flag
I have create my own NSOpenGLView class, right now the data that i want
I am new to Eclipse and Android programming in general but I have been

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.