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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:33:21+00:00 2026-05-31T04:33:21+00:00

i want to create a widget that when clicked on to open a dialog

  • 0

i want to create a widget that when clicked on to open a dialog with a autocompletetextview(FROM THE main.class) and execute functions from mainclass.. here is my widget class and please tell me what to put in android manifest also. thx

 public class AppWidget extends AppWidgetProvider
 {
@Override
public void onReceive(Context ctxt, Intent intent)
{
    if(intent.getAction()==null)
    {
        ctxt.startService(new Intent(ctxt,ToggleService.class));
    }
    else
    {
        super.onReceive(ctxt, intent);
    }

}

@Override
public void onUpdate(Context context,AppWidgetManager appWidgetManager, int [] appWidgetIds)
{
    context.startService(new Intent(context,ToggleService.class));
    //RemoteViews buildUpdate(context);
}

public static class ToggleService extends IntentService
    {
    public ToggleService() {
        super("AppWidget$ToggleService");

        }



@Override
protected void onHandleIntent(Intent intent)
{
    ComponentName me = new ComponentName(this,AppWidget.class);
    AppWidgetManager mgr= AppWidgetManager.getInstance(this);
    mgr.updateAppWidget(me,buildUpdate(this));
}

private RemoteViews buildUpdate(Context context)
{
    RemoteViews updateViews=new RemoteViews(context.getPackageName(),R.layout.widget);


    Intent i=new Intent(this, AppWidget.class);
    PendingIntent pi= PendingIntent.getBroadcast(context,0, i,0);
    updateViews.setOnClickPendingIntent(R.id.phoneState,pi);
    return updateViews;
}

}
}

widgetxml//

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView 

     android:id="@+id/phoneState"

     android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_launcher"
    />



</RelativeLayout>

// and widget_provider.xml in res/xml

     <?xml version="1.0" encoding="utf-8"?>
    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"

    android:minWidth="79px"
    android:minHeight="79px"
    android:updatePeriodMillis="1800000"
    android:initialLayout="@layout/widget">


<TextView

 android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Loading..." />

// and part from my manifest

   <receiver android:name=".AppWidget"
        android:label="Caller"
        android:icon="@drawable/ic_launcher" >
        <intent-filter >
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

        </intent-filter>
        <meta-data 
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_provider"
            />

    </receiver>
    <service android:name=".AppWidget$ToggleService"  />   
  • 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-31T04:33:22+00:00Added an answer on May 31, 2026 at 4:33 am

    Upadte your manifest.xml

    <receiver android:name=".AppWidget"
            android:label="Caller"
            android:icon="@drawable/ic_launcher" >
            <intent-filter >
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
     <action android:name="com.app.example.MyWidget.ACTION_WIDGET_CLICK_RECEIVER"/>
    
            </intent-filter>
            <meta-data 
                android:name="android.appwidget.provider"
                android:resource="@xml/widget_provider"
                />
    
        </receiver>
        <service android:name=".AppWidget$ToggleService"  />   
    

    and Update your AppWidgetProvider:

    public class MyWidget extends AppWidgetProvider {
            public static String ACTION_WIDGET_CLICK_RECEIVER = "ActionReceiverWidget";
    
            public static int appid[];
            public static RemoteViews rview;
            @Override
            public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
                    int[] appWidgetIds){
                updateWidgetState(context, ""); 
            }
            @Override
            public void onReceive(Context paramContext, Intent paramIntent)
              {
                 String str = paramIntent.getAction();
                if (paramIntent.getAction().equals(ACTION_WIDGET_CLICK_RECEIVER)) {
                    updateWidgetState(paramContext, str);   
                }
                else
                {
                        if ("android.appwidget.action.APPWIDGET_DELETED".equals(str))
                          {
                            int i = paramIntent.getExtras().getInt("appWidgetId", 0);
                            if (i == 0)
                            {
    
                            }
                            else
                            {
                                int[] arrayOfInt = new int[1];
                                arrayOfInt[0] = i;
                                onDeleted(paramContext, arrayOfInt);
                            }
                          }
                  super.onReceive(paramContext, paramIntent);
                }
              }
             static void updateWidgetState(Context paramContext, String paramString)
              {
                RemoteViews localRemoteViews = buildUpdate(paramContext, paramString);
                ComponentName localComponentName = new ComponentName(paramContext, MyWidget.class);
                AppWidgetManager.getInstance(paramContext).updateAppWidget(localComponentName, localRemoteViews);
              }
             private static RemoteViews buildUpdate(Context paramContext, String paramString)
              {
                // Toast.makeText(paramContext, "buildUpdate() ::"+paramString, Toast.LENGTH_SHORT).show();
                rview = new RemoteViews(paramContext.getPackageName(), R.layout.widget_layout);
                Intent active = new Intent(paramContext, MyWidget.class);
                active.setAction(ACTION_WIDGET_RECEIVER);
                active.putExtra("msg", "Message for Button 1");
                PendingIntent configPendingIntent = PendingIntent.getActivity(paramContext, 0, active, 0);
                rmViews.setOnClickPendingIntent(R.id.buttonus1, configPendingIntent);
                if(parmString.equals(ACTION_WIDGET_CLICK_RECEIVER))
                {
    
                   //open a dialog with a autocompletetextview
                 //your code for update and what you want on button click
    
                }  
                 return rview; 
              }
            @Override
            public void onEnabled(Context context){
                super.onEnabled(context);
               // Toast.makeText(context, "onEnabled()  ", Toast.LENGTH_SHORT).show();
            }
            // Called each time an instance of the App Widget is removed from the host
            @Override
            public void onDeleted(Context context, int [] appWidgetId){
                super.onDeleted(context, appWidgetId);
               // Toast.makeText(context, "onDeleted()  ", Toast.LENGTH_SHORT).show();
            }
            // Called when last instance of App Widget is deleted from the App Widget host.
            @Override
            public void onDisabled(Context context) {
                super.onDisabled(context);
               // Toast.makeText(context, "onDisabled()  ", Toast.LENGTH_SHORT).show();
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a tab/widget/thingymajiggy like the feedback-thing in this picture: That behaves
Please excuse me if I'm simple here, I want to create a simple widget
I want to create a Qt widget that can play incoming RTP streams where
I want to create a widget in Mac OS X that exists on the
i want to create a widget app that when added will start ConfigurationActivity which
I want to create a toolbar for a text widget that allows you to
I'm writing a popup widget that inherits from ui.dialog and I'm wondering if there
I want to create a custom widget that contains a QSpinBox. I want the
i want to create a widget depending on the class of the object, is
I want to create a photo browser web widget that can be embedded in

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.